group mml tests

This commit is contained in:
Arpad Ryszka 2017-10-27 18:30:39 +02:00
parent 6213503401
commit 6a14872b6e

View File

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