group mml tests
This commit is contained in:
parent
6213503401
commit
6a14872b6e
562
mml_test.go
562
mml_test.go
@ -9,7 +9,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMML(t *testing.T) {
|
func TestMML(t *testing.T) {
|
||||||
runTestsFile(t, "mml.parser", []testItem{{
|
s, err := openSyntaxFile("mml.parser")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("comment", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "empty",
|
title: "empty",
|
||||||
node: &Node{Name: "mml"},
|
node: &Node{Name: "mml"},
|
||||||
}, {
|
}, {
|
||||||
@ -88,7 +95,11 @@ func TestMML(t *testing.T) {
|
|||||||
To: 23,
|
To: 23,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("int", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "int",
|
title: "int",
|
||||||
text: "42",
|
text: "42",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -124,7 +135,11 @@ func TestMML(t *testing.T) {
|
|||||||
Name: "int",
|
Name: "int",
|
||||||
To: 4,
|
To: 4,
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("float", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "float, 0.",
|
title: "float, 0.",
|
||||||
text: "0.",
|
text: "0.",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -181,6 +196,23 @@ func TestMML(t *testing.T) {
|
|||||||
To: 9,
|
To: 9,
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
|
|
||||||
|
title: "float on a new line",
|
||||||
|
text: "f()\n.9",
|
||||||
|
nodes: []*Node{{
|
||||||
|
Name: "function-application",
|
||||||
|
Nodes: []*Node{{
|
||||||
|
Name: "symbol",
|
||||||
|
}},
|
||||||
|
}, {
|
||||||
|
Name: "float",
|
||||||
|
}},
|
||||||
|
ignorePosition: true,
|
||||||
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("string", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "string, empty",
|
title: "string, empty",
|
||||||
text: "\"\"",
|
text: "\"\"",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -215,7 +247,11 @@ func TestMML(t *testing.T) {
|
|||||||
Name: "string",
|
Name: "string",
|
||||||
To: 17,
|
To: 17,
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("bool", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "bool, true",
|
title: "bool, true",
|
||||||
text: "true",
|
text: "true",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -229,7 +265,11 @@ func TestMML(t *testing.T) {
|
|||||||
Name: "false",
|
Name: "false",
|
||||||
To: 5,
|
To: 5,
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("symbol", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "symbol",
|
title: "symbol",
|
||||||
text: "foo",
|
text: "foo",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -248,7 +288,11 @@ func TestMML(t *testing.T) {
|
|||||||
To: 8,
|
To: 8,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("list", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "empty list",
|
title: "empty list",
|
||||||
text: "[]",
|
text: "[]",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -277,26 +321,22 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
title: "list, new lines",
|
title: "list, new lines",
|
||||||
text: `[
|
text: "[ \n a \n b \n c \n ]",
|
||||||
a
|
|
||||||
b
|
|
||||||
c
|
|
||||||
]`,
|
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
Name: "list",
|
Name: "list",
|
||||||
To: 20,
|
To: 17,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 5,
|
From: 4,
|
||||||
To: 6,
|
To: 5,
|
||||||
}, {
|
}, {
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 10,
|
From: 8,
|
||||||
To: 11,
|
To: 9,
|
||||||
}, {
|
}, {
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 15,
|
From: 12,
|
||||||
To: 16,
|
To: 13,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
@ -360,7 +400,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("mutable list", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "mutable list",
|
title: "mutable list",
|
||||||
text: "~[a, b, c]",
|
text: "~[a, b, c]",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -380,7 +424,11 @@ func TestMML(t *testing.T) {
|
|||||||
To: 9,
|
To: 9,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("struct", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "empty struct",
|
title: "empty struct",
|
||||||
text: "{}",
|
text: "{}",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -550,7 +598,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("mutable struct", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "mutable struct",
|
title: "mutable struct",
|
||||||
text: "~{foo: 1}",
|
text: "~{foo: 1}",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -571,7 +623,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("channel", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "channel",
|
title: "channel",
|
||||||
text: "<>",
|
text: "<>",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -590,7 +646,11 @@ func TestMML(t *testing.T) {
|
|||||||
To: 3,
|
To: 3,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("boolean expressions", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "and expression",
|
title: "and expression",
|
||||||
text: "and(a, b, c)",
|
text: "and(a, b, c)",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -636,7 +696,11 @@ func TestMML(t *testing.T) {
|
|||||||
To: 10,
|
To: 10,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("function", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "function",
|
title: "function",
|
||||||
text: "fn () 42",
|
text: "fn () 42",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -699,42 +763,38 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
title: "function with args in new lines",
|
title: "function with args in new lines",
|
||||||
text: `fn (
|
text: "fn ( \n a \n b \n c ) [a, b, c]",
|
||||||
a
|
|
||||||
b
|
|
||||||
c
|
|
||||||
) [a, b, c]`,
|
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
Name: "function",
|
Name: "function",
|
||||||
To: 33,
|
To: 28,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 8,
|
From: 7,
|
||||||
To: 9,
|
To: 8,
|
||||||
}, {
|
}, {
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 13,
|
From: 11,
|
||||||
To: 14,
|
To: 12,
|
||||||
}, {
|
}, {
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 18,
|
From: 15,
|
||||||
To: 19,
|
To: 16,
|
||||||
}, {
|
}, {
|
||||||
Name: "list",
|
Name: "list",
|
||||||
From: 24,
|
From: 19,
|
||||||
To: 33,
|
To: 28,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 25,
|
From: 20,
|
||||||
To: 26,
|
To: 21,
|
||||||
}, {
|
}, {
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 28,
|
From: 23,
|
||||||
To: 29,
|
To: 24,
|
||||||
}, {
|
}, {
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 31,
|
From: 26,
|
||||||
To: 32,
|
To: 27,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
@ -780,7 +840,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("effect", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "effect",
|
title: "effect",
|
||||||
text: "fn ~ () 42",
|
text: "fn ~ () 42",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -792,7 +856,11 @@ func TestMML(t *testing.T) {
|
|||||||
To: 10,
|
To: 10,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("indexer", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "indexer",
|
title: "indexer",
|
||||||
text: "a[42]",
|
text: "a[42]",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -907,7 +975,11 @@ func TestMML(t *testing.T) {
|
|||||||
To: 9,
|
To: 9,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("symbol indexer", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "symbol indexer",
|
title: "symbol indexer",
|
||||||
text: "a.b",
|
text: "a.b",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -1034,19 +1106,142 @@ func TestMML(t *testing.T) {
|
|||||||
To: 7,
|
To: 7,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
title: "float on a new line",
|
})
|
||||||
text: "f()\n.9",
|
|
||||||
|
t.Run("symbol indexer", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
|
title: "symbol indexer",
|
||||||
|
text: "a.b",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
Name: "function-application",
|
Name: "indexer",
|
||||||
|
To: 3,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
|
To: 1,
|
||||||
|
}, {
|
||||||
|
Name: "symbol",
|
||||||
|
From: 2,
|
||||||
|
To: 3,
|
||||||
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Name: "float",
|
title: "symbol indexer, with string",
|
||||||
}},
|
text: "a.\"b\"",
|
||||||
ignorePosition: true,
|
nodes: []*Node{{
|
||||||
|
Name: "indexer",
|
||||||
|
To: 5,
|
||||||
|
Nodes: []*Node{{
|
||||||
|
Name: "symbol",
|
||||||
|
To: 1,
|
||||||
}, {
|
}, {
|
||||||
|
Name: "string",
|
||||||
|
From: 2,
|
||||||
|
To: 5,
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
}, {
|
||||||
|
title: "symbol indexer, with dynamic symbol",
|
||||||
|
text: "a.symbol(b)",
|
||||||
|
nodes: []*Node{{
|
||||||
|
Name: "indexer",
|
||||||
|
To: 11,
|
||||||
|
Nodes: []*Node{{
|
||||||
|
Name: "symbol",
|
||||||
|
To: 1,
|
||||||
|
}, {
|
||||||
|
Name: "dynamic-symbol",
|
||||||
|
From: 2,
|
||||||
|
To: 11,
|
||||||
|
Nodes: []*Node{{
|
||||||
|
Name: "symbol",
|
||||||
|
From: 9,
|
||||||
|
To: 10,
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
}, {
|
||||||
|
title: "chained symbol indexer",
|
||||||
|
text: "a.b.c.d",
|
||||||
|
nodes: []*Node{{
|
||||||
|
Name: "indexer",
|
||||||
|
To: 7,
|
||||||
|
Nodes: []*Node{{
|
||||||
|
Name: "indexer",
|
||||||
|
To: 5,
|
||||||
|
Nodes: []*Node{{
|
||||||
|
Name: "indexer",
|
||||||
|
To: 3,
|
||||||
|
Nodes: []*Node{{
|
||||||
|
Name: "symbol",
|
||||||
|
To: 1,
|
||||||
|
}, {
|
||||||
|
Name: "symbol",
|
||||||
|
From: 2,
|
||||||
|
To: 3,
|
||||||
|
}},
|
||||||
|
}, {
|
||||||
|
Name: "symbol",
|
||||||
|
From: 4,
|
||||||
|
To: 5,
|
||||||
|
}},
|
||||||
|
}, {
|
||||||
|
Name: "symbol",
|
||||||
|
From: 6,
|
||||||
|
To: 7,
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
}, {
|
||||||
|
title: "chained symbol indexer on new line",
|
||||||
|
text: "a\n.b\n.c",
|
||||||
|
nodes: []*Node{{
|
||||||
|
Name: "indexer",
|
||||||
|
To: 7,
|
||||||
|
Nodes: []*Node{{
|
||||||
|
Name: "indexer",
|
||||||
|
To: 4,
|
||||||
|
Nodes: []*Node{{
|
||||||
|
Name: "symbol",
|
||||||
|
To: 1,
|
||||||
|
}, {
|
||||||
|
Name: "symbol",
|
||||||
|
From: 3,
|
||||||
|
To: 4,
|
||||||
|
}},
|
||||||
|
}, {
|
||||||
|
Name: "symbol",
|
||||||
|
From: 6,
|
||||||
|
To: 7,
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
}, {
|
||||||
|
title: "chained symbol indexer on new line after dot",
|
||||||
|
text: "a.\nb.\nc",
|
||||||
|
nodes: []*Node{{
|
||||||
|
Name: "indexer",
|
||||||
|
To: 7,
|
||||||
|
Nodes: []*Node{{
|
||||||
|
Name: "indexer",
|
||||||
|
To: 4,
|
||||||
|
Nodes: []*Node{{
|
||||||
|
Name: "symbol",
|
||||||
|
To: 1,
|
||||||
|
}, {
|
||||||
|
Name: "symbol",
|
||||||
|
From: 3,
|
||||||
|
To: 4,
|
||||||
|
}},
|
||||||
|
}, {
|
||||||
|
Name: "symbol",
|
||||||
|
From: 6,
|
||||||
|
To: 7,
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("function application", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "function application",
|
title: "function application",
|
||||||
text: "f()",
|
text: "f()",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -1219,7 +1414,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("if", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "if",
|
title: "if",
|
||||||
text: "if a { b() }",
|
text: "if a { b() }",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -1277,67 +1476,66 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
title: "if, else if, else if, else",
|
title: "if, else if, else if, else",
|
||||||
text: `
|
text: "if a { b }\nelse if c { d }\nelse if e { f }\nelse { g }",
|
||||||
if a { b }
|
|
||||||
else if c { d }
|
|
||||||
else if e { f }
|
|
||||||
else { g }
|
|
||||||
`,
|
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
Name: "if",
|
Name: "if",
|
||||||
From: 4,
|
From: 0,
|
||||||
To: 66,
|
To: 53,
|
||||||
|
Nodes: []*Node{{
|
||||||
|
Name: "symbol",
|
||||||
|
From: 3,
|
||||||
|
To: 4,
|
||||||
|
}, {
|
||||||
|
Name: "block",
|
||||||
|
From: 5,
|
||||||
|
To: 10,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 7,
|
From: 7,
|
||||||
To: 8,
|
To: 8,
|
||||||
}, {
|
|
||||||
Name: "block",
|
|
||||||
From: 9,
|
|
||||||
To: 14,
|
|
||||||
Nodes: []*Node{{
|
|
||||||
Name: "symbol",
|
|
||||||
From: 11,
|
|
||||||
To: 12,
|
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 26,
|
From: 19,
|
||||||
To: 27,
|
To: 20,
|
||||||
}, {
|
}, {
|
||||||
Name: "block",
|
Name: "block",
|
||||||
From: 28,
|
From: 21,
|
||||||
To: 33,
|
To: 26,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 30,
|
From: 23,
|
||||||
To: 31,
|
To: 24,
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 45,
|
From: 35,
|
||||||
To: 46,
|
To: 36,
|
||||||
}, {
|
}, {
|
||||||
Name: "block",
|
Name: "block",
|
||||||
From: 47,
|
From: 37,
|
||||||
To: 52,
|
To: 42,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 49,
|
From: 39,
|
||||||
To: 50,
|
To: 40,
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Name: "block",
|
Name: "block",
|
||||||
From: 61,
|
From: 48,
|
||||||
To: 66,
|
To: 53,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 63,
|
From: 50,
|
||||||
To: 64,
|
To: 51,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("switch", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "switch, empty",
|
title: "switch, empty",
|
||||||
text: "switch {default:}",
|
text: "switch {default:}",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -1454,65 +1652,55 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
title: "switch, all new lines",
|
title: "switch, all new lines",
|
||||||
text: `switch
|
text: "switch \n a \n { \n case \n b \n : \n c \n case \n d \n : \n e \n default \n : \n f \n }",
|
||||||
a
|
|
||||||
{
|
|
||||||
case
|
|
||||||
b
|
|
||||||
:
|
|
||||||
c
|
|
||||||
case
|
|
||||||
d
|
|
||||||
:
|
|
||||||
e
|
|
||||||
default
|
|
||||||
:
|
|
||||||
f
|
|
||||||
}`,
|
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
Name: "switch",
|
Name: "switch",
|
||||||
To: 87,
|
To: 74,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 10,
|
From: 9,
|
||||||
To: 11,
|
To: 10,
|
||||||
}, {
|
}, {
|
||||||
Name: "case",
|
Name: "case",
|
||||||
From: 20,
|
From: 17,
|
||||||
To: 34,
|
To: 29,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 28,
|
From: 24,
|
||||||
To: 29,
|
To: 25,
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 38,
|
From: 32,
|
||||||
To: 39,
|
To: 33,
|
||||||
}, {
|
}, {
|
||||||
Name: "case",
|
Name: "case",
|
||||||
From: 43,
|
From: 36,
|
||||||
To: 57,
|
To: 48,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
|
Name: "symbol",
|
||||||
|
From: 43,
|
||||||
|
To: 44,
|
||||||
|
}},
|
||||||
|
}, {
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 51,
|
From: 51,
|
||||||
To: 52,
|
To: 52,
|
||||||
}},
|
|
||||||
}, {
|
|
||||||
Name: "symbol",
|
|
||||||
From: 61,
|
|
||||||
To: 62,
|
|
||||||
}, {
|
}, {
|
||||||
Name: "default",
|
Name: "default",
|
||||||
From: 66,
|
From: 55,
|
||||||
To: 78,
|
To: 66,
|
||||||
}, {
|
}, {
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 82,
|
From: 69,
|
||||||
To: 83,
|
To: 70,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("match", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "match expression, empty",
|
title: "match expression, empty",
|
||||||
text: "match a {}",
|
text: "match a {}",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -1526,49 +1714,47 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
title: "match expression",
|
title: "match expression",
|
||||||
text: `match a {
|
text: "match a {\ncase [first, ...rest]: first\n}",
|
||||||
case [first, ...rest]: first
|
|
||||||
}`,
|
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
Name: "match",
|
Name: "match",
|
||||||
To: 45,
|
To: 40,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 6,
|
From: 6,
|
||||||
To: 7,
|
To: 7,
|
||||||
}, {
|
}, {
|
||||||
Name: "match-case",
|
Name: "match-case",
|
||||||
From: 13,
|
From: 10,
|
||||||
To: 35,
|
To: 32,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "list-type",
|
Name: "list-type",
|
||||||
From: 18,
|
From: 15,
|
||||||
To: 34,
|
To: 31,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "list-destructure-type",
|
Name: "list-destructure-type",
|
||||||
From: 19,
|
From: 16,
|
||||||
To: 33,
|
To: 30,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "destructure-item",
|
Name: "destructure-item",
|
||||||
From: 19,
|
From: 16,
|
||||||
To: 24,
|
To: 21,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 19,
|
From: 16,
|
||||||
To: 24,
|
To: 21,
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Name: "collect-destructure-item",
|
Name: "collect-destructure-item",
|
||||||
From: 26,
|
From: 23,
|
||||||
To: 33,
|
To: 30,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "destructure-item",
|
Name: "destructure-item",
|
||||||
From: 29,
|
From: 26,
|
||||||
To: 33,
|
To: 30,
|
||||||
Nodes: []*Node{{
|
Nodes: []*Node{{
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 29,
|
From: 26,
|
||||||
To: 33,
|
To: 30,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
@ -1576,8 +1762,8 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Name: "symbol",
|
Name: "symbol",
|
||||||
From: 36,
|
From: 33,
|
||||||
To: 41,
|
To: 38,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
@ -1831,7 +2017,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("send/receive", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "receive op",
|
title: "receive op",
|
||||||
text: "<-chan",
|
text: "<-chan",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -1856,13 +2046,16 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("select", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "select, empty",
|
title: "select, empty",
|
||||||
text: `select {
|
text: "select {\n}",
|
||||||
}`,
|
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
Name: "select",
|
Name: "select",
|
||||||
To: 12,
|
To: 10,
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
title: "select",
|
title: "select",
|
||||||
@ -1976,7 +2169,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("block", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "block",
|
title: "block",
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
text: "{ f() }",
|
text: "{ f() }",
|
||||||
@ -1989,7 +2186,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("go", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "go",
|
title: "go",
|
||||||
text: "go f()",
|
text: "go f()",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -2024,7 +2225,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("require", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "require, dot, equal",
|
title: "require, dot, equal",
|
||||||
text: "require . = \"mml/foo\"",
|
text: "require . = \"mml/foo\"",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -2129,7 +2334,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("expression group", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "expression group",
|
title: "expression group",
|
||||||
text: "(fn (a) a)(a)",
|
text: "(fn (a) a)(a)",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -2146,7 +2355,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("unary", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "unary operator",
|
title: "unary operator",
|
||||||
text: "!foo",
|
text: "!foo",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -2158,7 +2371,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("binary", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "binary 0",
|
title: "binary 0",
|
||||||
text: "a * b",
|
text: "a * b",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -2308,7 +2525,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("ternary", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "ternary expression",
|
title: "ternary expression",
|
||||||
text: "a ? b : c",
|
text: "a ? b : c",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -2391,7 +2612,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("loop", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "infinite loop",
|
title: "infinite loop",
|
||||||
text: "for {}",
|
text: "for {}",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -2525,7 +2750,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("assign", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "assign, eq",
|
title: "assign, eq",
|
||||||
text: "a = b",
|
text: "a = b",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -2595,7 +2824,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("define", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "define, eq",
|
title: "define, eq",
|
||||||
text: "let a = b",
|
text: "let a = b",
|
||||||
nodes: []*Node{{
|
nodes: []*Node{{
|
||||||
@ -2801,7 +3034,11 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
}, {
|
}})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("type", func(t *testing.T) {
|
||||||
|
runTestsSyntax(t, s, []testItem{{
|
||||||
title: "type constraint",
|
title: "type constraint",
|
||||||
text: `
|
text: `
|
||||||
type a fn ([]) int
|
type a fn ([]) int
|
||||||
@ -2873,6 +3110,7 @@ func TestMML(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
ignorePosition: true,
|
ignorePosition: true,
|
||||||
}})
|
}})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMMLFile(t *testing.T) {
|
func TestMMLFile(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user