Skip to content

Commit 3a5be14

Browse files
committed
spec: add required specs
1 parent 91038fb commit 3a5be14

File tree

1,017 files changed

+34071
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,017 files changed

+34071
-30
lines changed

spec/ast/node_spec.cr

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require "../spec_helper"
2+
3+
describe MoonScript::Ast::Node do
4+
context "#contains?" do
5+
it "checks if the location is contained within the node" do
6+
example =
7+
<<-MOON
8+
component Test {
9+
fun render : Html {
10+
<div></div>
11+
}
12+
}
13+
MOON
14+
15+
node =
16+
MoonScript::Parser
17+
.parse(example, "example.moonscript")
18+
.components
19+
.first
20+
.functions
21+
.first
22+
23+
{node.from.line, node.from.column}.should eq({2, 2})
24+
25+
# actually {4, 2} but all parsers go over by 1
26+
{node.to.line, node.to.column}.should eq({4, 3})
27+
28+
# First line
29+
node.contains?(2, 1).should eq(false) # space before `f`
30+
node.contains?(2, 3).should eq(true) # `f` of `fun`
31+
32+
# Middle line
33+
node.contains?(3, 0).should eq(true)
34+
node.contains?(3, 9).should eq(true)
35+
node.contains?(3, 1000).should eq(true)
36+
37+
# End line
38+
node.contains?(4, 2).should eq(true) # `}`
39+
node.contains?(4, 3).should eq(false) # space after `}`
40+
end
41+
end
42+
end

spec/compilers/access

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
type X {
2+
name : String
3+
}
4+
5+
component Main {
6+
fun render : String {
7+
{ name: "test" }.name
8+
}
9+
}
10+
--------------------------------------------------------------------------------
11+
import { record as A } from "./runtime.js";
12+
13+
export const
14+
a = A(`X`),
15+
B = () => {
16+
return a({
17+
name: `test`
18+
}).name
19+
};

spec/compilers/access_deep

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
type Locale {
2+
level1: Level1
3+
}
4+
5+
type Level1 {
6+
level2: Level2
7+
}
8+
9+
type Level2 {
10+
name : String
11+
}
12+
13+
store Settings {
14+
state locale : Locale = { level1: { level2: { name: "Test" }} }
15+
}
16+
17+
component Main {
18+
fun render : String {
19+
Settings.locale.level1.level2.name
20+
}
21+
}
22+
--------------------------------------------------------------------------------
23+
import {
24+
signal as B,
25+
record as A
26+
} from "./runtime.js";
27+
28+
export const
29+
a = A(`Level2`),
30+
b = A(`Level1`),
31+
c = A(`Locale`),
32+
d = B(c({
33+
level1: b({
34+
level2: a({
35+
name: `Test`
36+
})
37+
})
38+
})),
39+
C = () => {
40+
return d.value.level1.level2.name
41+
};

spec/compilers/argument

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
component Main {
2+
fun test (a : String, b : Number) : Number {
3+
b
4+
}
5+
6+
fun render : String {
7+
test("", 0)
8+
9+
""
10+
}
11+
}
12+
--------------------------------------------------------------------------------
13+
export const A = () => {
14+
const a = (b, c) => {
15+
return c
16+
};
17+
a(``, 0);
18+
return ``
19+
};

spec/compilers/argument_with_default

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
component Main {
2+
fun test (a : String, b : Number = 0) : Number {
3+
b
4+
}
5+
6+
fun render : String {
7+
test("")
8+
9+
""
10+
}
11+
}
12+
--------------------------------------------------------------------------------
13+
export const A = () => {
14+
const a = (b, c = 0) => {
15+
return c
16+
};
17+
a(``);
18+
return ``
19+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
component Main {
2+
fun render : String {
3+
let test =
4+
(a : String, b : Number = 0) : Number {
5+
b
6+
}
7+
8+
test("")
9+
10+
""
11+
}
12+
}
13+
--------------------------------------------------------------------------------
14+
export const A = () => {
15+
const a = (b, c = 0) => {
16+
return c
17+
};
18+
a(``);
19+
return ``
20+
};

spec/compilers/array_literal

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
component Main {
2+
fun render : String {
3+
[
4+
"Hello",
5+
"Blah",
6+
"Joe"
7+
]
8+
9+
""
10+
}
11+
}
12+
--------------------------------------------------------------------------------
13+
export const A = () => {
14+
[
15+
`Hello`,
16+
`Blah`,
17+
`Joe`
18+
];
19+
return ``
20+
};

spec/compilers/block

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
component Main {
2+
fun render : String {
3+
let a = "Some string..."
4+
5+
a + ", other string..."
6+
}
7+
}
8+
--------------------------------------------------------------------------------
9+
export const A = () => {
10+
const a = `Some string...`;
11+
return a + `, other string...`
12+
};

spec/compilers/block_with_await

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
component Main {
2+
fun promise : Promise(String) {
3+
`` as Promise(String)
4+
}
5+
6+
fun promiseTest : Promise(String) {
7+
await promise()
8+
}
9+
10+
fun render : String {
11+
promiseTest()
12+
13+
"Hello"
14+
}
15+
}
16+
--------------------------------------------------------------------------------
17+
export const A = () => {
18+
const
19+
a = () => {
20+
return undefined
21+
},
22+
b = async () => {
23+
return await a()
24+
};
25+
b();
26+
return `Hello`
27+
};
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
type Test {
2+
A(String)
3+
B(String)
4+
}
5+
6+
component Main {
7+
fun render : String {
8+
let Test.A(a) =
9+
Test.A("Some string...") or return "RETURN"
10+
11+
a
12+
}
13+
}
14+
--------------------------------------------------------------------------------
15+
import {
16+
patternVariable as E,
17+
destructure as B,
18+
newVariant as C,
19+
pattern as D,
20+
variant as A
21+
} from "./runtime.js";
22+
23+
export const
24+
F = A(1, `Test.A`),
25+
G = A(1, `Test.B`),
26+
H = () => {
27+
const a = B(C(F)(`Some string...`), D(F, [E]));
28+
if (a === false) {
29+
return `RETURN`
30+
};
31+
const [b] = a;
32+
return b
33+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
type Test {
2+
A(String)
3+
B(String)
4+
}
5+
6+
component Main {
7+
fun render : String {
8+
{
9+
let Test.A(a) =
10+
await Test.A("Some string...") or return "RETURN"
11+
12+
a
13+
}
14+
15+
""
16+
}
17+
}
18+
--------------------------------------------------------------------------------
19+
import {
20+
patternVariable as E,
21+
destructure as B,
22+
newVariant as C,
23+
pattern as D,
24+
variant as A
25+
} from "./runtime.js";
26+
27+
export const
28+
F = A(1, `Test.A`),
29+
G = A(1, `Test.B`),
30+
H = () => {
31+
(async () => {
32+
const a = B(await C(F)(`Some string...`), D(F, [E]));
33+
if (a === false) {
34+
return `RETURN`
35+
};
36+
const [b] = a;
37+
return b
38+
})();
39+
return ``
40+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
component Main {
2+
fun render : String {
3+
let {a, b} = {"Some string...", "B"}
4+
5+
a + ", other string..."
6+
}
7+
}
8+
--------------------------------------------------------------------------------
9+
export const A = () => {
10+
const [
11+
a,
12+
b
13+
] = [
14+
`Some string...`,
15+
`B`
16+
];
17+
return a + `, other string...`
18+
};

spec/compilers/bool_literal_false

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
component Main {
2+
fun render : String {
3+
false
4+
5+
""
6+
}
7+
}
8+
--------------------------------------------------------------------------------
9+
export const A = () => {
10+
false;
11+
return ``
12+
};

spec/compilers/bool_literal_true

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
component Main {
2+
fun render : String {
3+
true
4+
5+
""
6+
}
7+
}
8+
--------------------------------------------------------------------------------
9+
export const A = () => {
10+
true;
11+
return ``
12+
};

spec/compilers/bracket_access

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
type Maybe(a) {
2+
Nothing
3+
Just(a)
4+
}
5+
6+
component Main {
7+
fun render : String {
8+
[
9+
"Hello",
10+
"Blah",
11+
"Joe"
12+
][1]
13+
14+
[][1]
15+
16+
{ "key" => "value" }["key"]
17+
18+
""
19+
}
20+
}
21+
--------------------------------------------------------------------------------
22+
import {
23+
bracketAccess as B,
24+
mapAccess as C,
25+
variant as A
26+
} from "./runtime.js";
27+
28+
export const
29+
D = A(0, `Maybe.Nothing`),
30+
E = A(1, `Maybe.Just`),
31+
F = () => {
32+
B([
33+
`Hello`,
34+
`Blah`,
35+
`Joe`
36+
], 1, E, D);
37+
B([], 1, E, D);
38+
C([[
39+
`key`,
40+
`value`
41+
]], `key`, E, D);
42+
return ``
43+
};

0 commit comments

Comments
 (0)