Fix bugs, add propper tests

This commit is contained in:
2026-02-03 13:20:23 +02:00
parent 081ff9a27a
commit 4b61adea5d
58 changed files with 1103 additions and 285 deletions

View File

@@ -1,55 +0,0 @@
Program {
ast: Block(
[
Statement(
LocBox {
inner: Enum(
Enum {
name: Ident(
"Foo",
),
fields: [],
},
),
loc: Loc {
file: "parser/enumerations.mcl",
line: 1,
col: 5,
},
},
),
Statement(
LocBox {
inner: Enum(
Enum {
name: Ident(
"Bar",
),
fields: [
Ident(
"A",
),
Ident(
"B",
),
Ident(
"C",
),
],
},
),
loc: Loc {
file: "parser/enumerations.mcl",
line: 3,
col: 5,
},
},
),
],
),
structs: {},
enums: {},
types: {},
functions: {},
member_functions: {},
}

View File

@@ -1,7 +0,0 @@
enum Foo {}
enum Bar {
A,
B,
C,
}

3
tests/parser/expr.rs Normal file
View File

@@ -0,0 +1,3 @@

View File

@@ -1,908 +0,0 @@
Program {
ast: Block(
[
Statement(
LocBox {
inner: Let {
name: Ident(
"a",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: EqEq,
left: LocBox {
inner: BinOp {
typ: Star,
left: LocBox {
inner: Literal(
Number(
Number {
val: 1,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 1,
col: 10,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 3,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 1,
col: 14,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 1,
col: 12,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 4,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 1,
col: 18,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 1,
col: 16,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 1,
col: 4,
},
},
),
Statement(
LocBox {
inner: Let {
name: Ident(
"b",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: EqEq,
left: LocBox {
inner: BinOp {
typ: Div,
left: LocBox {
inner: Literal(
Number(
Number {
val: 3,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 10,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 4,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 12,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 11,
},
},
right: LocBox {
inner: UnOp {
typ: Star,
right: LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 17,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 16,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 14,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 4,
},
},
),
Statement(
LocBox {
inner: Let {
name: Ident(
"c",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: Div,
left: LocBox {
inner: Group(
LocBox {
inner: PtrFieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 11,
},
},
),
right: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"b",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 13,
},
},
),
right: LocBox {
inner: PtrFieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"c",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 15,
},
},
),
right: LocBox {
inner: Path(
Path(
[
Ident(
"d",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 17,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 16,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 14,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 12,
},
},
),
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 10,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 2,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 22,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 20,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 4,
},
},
),
Statement(
LocBox {
inner: Let {
name: Ident(
"d",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: Div,
left: LocBox {
inner: Literal(
Number(
Number {
val: 2,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 10,
},
},
right: LocBox {
inner: PtrFieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 14,
},
},
),
right: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"b",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 16,
},
},
),
right: LocBox {
inner: PtrFieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"c",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 18,
},
},
),
right: LocBox {
inner: Path(
Path(
[
Ident(
"d",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 20,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 19,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 17,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 15,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 12,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 4,
},
},
),
Statement(
LocBox {
inner: Let {
name: Ident(
"e",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: Div,
left: LocBox {
inner: PtrFieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 10,
},
},
),
right: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"b",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 12,
},
},
),
right: LocBox {
inner: PtrFieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"c",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 14,
},
},
),
right: LocBox {
inner: Path(
Path(
[
Ident(
"d",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 16,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 15,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 13,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 11,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 2,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 20,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 18,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 4,
},
},
),
Statement(
LocBox {
inner: Let {
name: Ident(
"f",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: Div,
left: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 10,
},
},
),
right: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"b",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 12,
},
},
),
right: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"c",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 14,
},
},
),
right: LocBox {
inner: Path(
Path(
[
Ident(
"d",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 16,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 15,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 13,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 11,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 2,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 20,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 18,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 4,
},
},
),
Statement(
LocBox {
inner: Let {
name: Ident(
"g",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: Star,
left: LocBox {
inner: ArrayIndex {
name: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 10,
},
},
),
right: LocBox {
inner: Path(
Path(
[
Ident(
"b",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 12,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 11,
},
},
index: LocBox {
inner: UnOp {
typ: Star,
right: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 15,
},
},
),
right: LocBox {
inner: Path(
Path(
[
Ident(
"c",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 17,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 16,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 14,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 13,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 5,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 22,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 20,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 4,
},
},
),
],
),
structs: {},
enums: {},
types: {},
functions: {},
member_functions: {},
}

View File

@@ -1,8 +0,0 @@
let a = 1 * 3 == 4;
let b = 3/4 == *a;
let c = (a->b.c->d) / 2;
let d = 2 / a->b.c->d;
let e = a->b.c->d / 2;
let f = a.b.c.d / 2;
let g = a.b[*a.c] * 5;

View File

@@ -1,306 +0,0 @@
Program {
ast: Block(
[
Statement(
LocBox {
inner: Fn(
Function {
struct_name: None,
name: Ident(
"main",
),
params: [
(
Ident(
"argc",
),
LocBox {
inner: Owned(
Ident(
"i32",
),
),
loc: Loc {
file: "parser/functions.mcl",
line: 1,
col: 18,
},
},
),
(
Ident(
"argv",
),
LocBox {
inner: Ref {
inner: Array {
inner: Owned(
Ident(
"Str",
),
),
},
mutable: false,
},
loc: Loc {
file: "parser/functions.mcl",
line: 1,
col: 27,
},
},
),
],
ret_type: Some(
LocBox {
inner: Owned(
Ident(
"i32",
),
),
loc: Loc {
file: "parser/functions.mcl",
line: 1,
col: 39,
},
},
),
qual_const: false,
qual_extern: None,
body: Some(
Block(
[
Expr(
LocBox {
inner: Return(
Some(
LocBox {
inner: Literal(
Number(
Number {
val: 0,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/functions.mcl",
line: 2,
col: 13,
},
},
),
),
loc: Loc {
file: "parser/functions.mcl",
line: 2,
col: 11,
},
},
),
],
),
),
},
),
loc: Loc {
file: "parser/functions.mcl",
line: 1,
col: 3,
},
},
),
Statement(
LocBox {
inner: Fn(
Function {
struct_name: Some(
Ident(
"Baz",
),
),
name: Ident(
"main",
),
params: [
(
Ident(
"self",
),
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Baz",
),
),
mutable: true,
},
loc: Loc {
file: "parser/functions.mcl",
line: 4,
col: 20,
},
},
),
(
Ident(
"a",
),
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Foo",
),
),
mutable: false,
},
loc: Loc {
file: "parser/functions.mcl",
line: 4,
col: 33,
},
},
),
(
Ident(
"b",
),
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Bar",
),
),
mutable: true,
},
loc: Loc {
file: "parser/functions.mcl",
line: 4,
col: 42,
},
},
),
],
ret_type: Some(
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Nya",
),
),
mutable: false,
},
loc: Loc {
file: "parser/functions.mcl",
line: 4,
col: 54,
},
},
),
qual_const: false,
qual_extern: None,
body: None,
},
),
loc: Loc {
file: "parser/functions.mcl",
line: 4,
col: 3,
},
},
),
Statement(
LocBox {
inner: Fn(
Function {
struct_name: Some(
Ident(
"Baz",
),
),
name: Ident(
"main",
),
params: [
(
Ident(
"a",
),
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Foo",
),
),
mutable: false,
},
loc: Loc {
file: "parser/functions.mcl",
line: 5,
col: 17,
},
},
),
(
Ident(
"b",
),
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Bar",
),
),
mutable: true,
},
loc: Loc {
file: "parser/functions.mcl",
line: 5,
col: 26,
},
},
),
],
ret_type: Some(
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Nya",
),
),
mutable: false,
},
loc: Loc {
file: "parser/functions.mcl",
line: 5,
col: 38,
},
},
),
qual_const: false,
qual_extern: None,
body: None,
},
),
loc: Loc {
file: "parser/functions.mcl",
line: 5,
col: 3,
},
},
),
],
),
structs: {},
enums: {},
types: {},
functions: {},
member_functions: {},
}

View File

@@ -1,5 +0,0 @@
fn main(argc: i32, argv: &[Str]) -> i32 {
return 0;
}
fn Baz.main(self: &mut Baz, a: &Foo, b: &mut Bar) -> &Nya;
fn Baz.main(a: &Foo, b: &mut Bar) -> &Nya;

View File

@@ -1,70 +0,0 @@
Program {
ast: Block(
[
Expr(
LocBox {
inner: If(
IfExpr {
test: LocBox {
inner: BinOp {
typ: Gt,
left: LocBox {
inner: Path(
Path(
[
Ident(
"i",
),
],
),
),
loc: Loc {
file: "parser/if-statements.mcl",
line: 2,
col: 5,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 3,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/if-statements.mcl",
line: 2,
col: 9,
},
},
},
loc: Loc {
file: "parser/if-statements.mcl",
line: 2,
col: 7,
},
},
body: Block(
[],
),
else_if: None,
},
),
loc: Loc {
file: "parser/if-statements.mcl",
line: 2,
col: 3,
},
},
),
],
),
structs: {},
enums: {},
types: {},
functions: {},
member_functions: {},
}

View File

@@ -1,18 +0,0 @@
if i > 3 {
}
if 1 {
} else {
}
if 1 {
} else if a > 3 {
} else {
}

View File

@@ -1,212 +0,0 @@
Program {
ast: Block(
[
Expr(
LocBox {
inner: ForLoop {
init: Statement(
LocBox {
inner: Let {
name: Ident(
"i",
),
typ: None,
val: Some(
LocBox {
inner: Literal(
Number(
Number {
val: 0,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 14,
},
},
),
},
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 8,
},
},
),
test: LocBox {
inner: BinOp {
typ: Lt,
left: LocBox {
inner: Path(
Path(
[
Ident(
"i",
),
],
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 17,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 10,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 22,
},
},
},
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 19,
},
},
on_loop: LocBox {
inner: BinOp {
typ: AddEq,
left: LocBox {
inner: Path(
Path(
[
Ident(
"i",
),
],
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 25,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 1,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 29,
},
},
},
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 27,
},
},
body: Block(
[],
),
},
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 4,
},
},
),
Expr(
LocBox {
inner: WhileLoop {
test: LocBox {
inner: BinOp {
typ: Gt,
left: LocBox {
inner: Path(
Path(
[
Ident(
"i",
),
],
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 2,
col: 8,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 3,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 2,
col: 12,
},
},
},
loc: Loc {
file: "parser/loops.mcl",
line: 2,
col: 10,
},
},
body: Block(
[],
),
},
loc: Loc {
file: "parser/loops.mcl",
line: 2,
col: 6,
},
},
),
Expr(
LocBox {
inner: InfLoop {
body: Block(
[],
),
},
loc: Loc {
file: "parser/loops.mcl",
line: 3,
col: 5,
},
},
),
],
),
structs: {},
enums: {},
types: {},
functions: {},
member_functions: {},
}

View File

@@ -1,3 +0,0 @@
for let i = 0; i < 10; i += 1 {}
while i > 3 {}
loop {}

3
tests/parser/mod.rs Normal file
View File

@@ -0,0 +1,3 @@
mod expr;
mod stat;
mod typ;

0
tests/parser/stat.rs Normal file
View File

View File

@@ -1,66 +0,0 @@
Program {
ast: Block(
[
Statement(
LocBox {
inner: Struct(
Struct {
name: Ident(
"foo_t",
),
fields: [],
},
),
loc: Loc {
file: "parser/structs.mcl",
line: 2,
col: 7,
},
},
),
Statement(
LocBox {
inner: Struct(
Struct {
name: Ident(
"bar_t",
),
fields: [
(
Ident(
"a",
),
LocBox {
inner: Ref {
inner: Owned(
Ident(
"bar_t",
),
),
mutable: false,
},
loc: Loc {
file: "parser/structs.mcl",
line: 5,
col: 9,
},
},
),
],
},
),
loc: Loc {
file: "parser/structs.mcl",
line: 4,
col: 7,
},
},
),
],
),
structs: {},
enums: {},
types: {},
functions: {},
member_functions: {},
}

View File

@@ -1,6 +0,0 @@
struct foo_t {}
struct bar_t {
a: &bar_t
}

190
tests/parser/typ.rs Normal file
View File

@@ -0,0 +1,190 @@
use std::vec;
use mclangc::{common::{Loc, loc::LocBox}, parser::{self, ast::{Ident, Keyword, Program, Punctuation, TokenType, statement::{Enum, Struct}, typ::Type}}, tokeniser::Token, validator::predefined::{BuiltinType, get_builtin_from_name, load_builtin}};
fn get_prog() -> Program {
let mut prog = Program::default();
load_builtin(&mut prog);
let loc = Loc::default();
prog.structs.insert(Ident::new("MyStruct"), LocBox::new(&loc, Struct {
name: Ident::new("MyStruct"),
fields: vec![
(Ident::new("foo"), LocBox::new(&loc, BuiltinType::usize())),
(Ident::new("bar"), LocBox::new(&loc, BuiltinType::bool())),
(Ident::new("baz"), LocBox::new(&loc, Type::Owned(Ident::new("str")).as_ref())),
]
}));
prog.enums.insert(Ident::new("MyEnum"), LocBox::new(&loc, Enum {
name: Ident::new("MyEnum"),
fields: vec![],
}));
prog
}
#[test]
fn parse_type_named_struct() {
let mut tokens = vec![
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct"))))
}
#[test]
fn parse_type_named_enum() {
let mut tokens = vec![
Token::new_test(TokenType::Ident(Ident::new("MyEnum")))
];
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyEnum"))))
}
#[test]
fn parse_type_ref() {
let mut tokens = vec![
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
tokens.reverse();
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct")).as_ref()))
}
#[test]
fn parse_type_ref2() {
let mut tokens = vec![
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
tokens.reverse();
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct")).as_ref().as_ref()))
}
#[test]
fn parse_type_ref3() {
let mut tokens = vec![
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
tokens.reverse();
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct")).as_ref().as_ref().as_ref()))
}
#[test]
fn parse_type_mut_ref() {
let mut tokens = vec![
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Keyword(Keyword::Mut)),
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
tokens.reverse();
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct")).as_ref_mut()))
}
#[test]
fn parse_type_mut_ref2() {
let mut tokens = vec![
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Keyword(Keyword::Mut)),
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Keyword(Keyword::Mut)),
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
tokens.reverse();
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct")).as_ref_mut().as_ref_mut()))
}
#[test]
fn parse_type_mut_ref3() {
let mut tokens = vec![
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Keyword(Keyword::Mut)),
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Keyword(Keyword::Mut)),
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Keyword(Keyword::Mut)),
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
tokens.reverse();
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct")).as_ref_mut().as_ref_mut().as_ref_mut()))
}
fn test_builtin(s: &str) {
let mut tokens = vec![
Token::new_test(TokenType::Ident(Ident::new(s)))
];
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), get_builtin_from_name(s).unwrap()))
}
#[test]
fn parse_type_builtin_usize() {
test_builtin("usize");
}
#[test]
fn parse_type_builtin_isize() {
test_builtin("isize");
}
#[test]
fn parse_type_builtin_u8() {
test_builtin("u8");
}
#[test]
fn parse_type_builtin_i8() {
test_builtin("i8");
}
#[test]
fn parse_type_builtin_u16() {
test_builtin("u16");
}
#[test]
fn parse_type_builtin_i16() {
test_builtin("i16");
}
#[test]
fn parse_type_builtin_u32() {
test_builtin("u32");
}
#[test]
fn parse_type_builtin_i32() {
test_builtin("i32");
}
#[test]
fn parse_type_builtin_u64() {
test_builtin("u64");
}
#[test]
fn parse_type_builtin_i64() {
test_builtin("i64");
}
#[test]
fn parse_type_builtin_void() {
test_builtin("void");
}
#[test]
fn parse_type_builtin_char() {
test_builtin("char");
}
#[test]
fn parse_type_builtin_bool() {
test_builtin("bool");
}