Skip to content

Commit 149c060

Browse files
committed
Add test cases for language annotation support
1 parent 2c03054 commit 149c060

File tree

5 files changed

+463
-58
lines changed

5 files changed

+463
-58
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
# Basic language annotation cases
3+
luaScript = /* lua */ ''
4+
print("Hello, world!")
5+
local x = 42
6+
'';
7+
8+
# With extra whitespace
9+
jsCode = /* javascript */ ''
10+
console.log("Hello from JS");
11+
const x = 42;
12+
'';
13+
14+
# missing whitespace after comment
15+
noSpace = /*python*/''
16+
print("No space after comment")
17+
'';
18+
19+
# Multiple language annotations in same expression
20+
mixedCode = {
21+
lua = /* lua */ ''
22+
print("Lua code")
23+
'';
24+
python = /* python */ ''
25+
print("Python code")
26+
'';
27+
};
28+
29+
# Language annotation with indented multiline string
30+
indentedCode = {
31+
script = /* python */ ''
32+
import os
33+
def main():
34+
print("Indented Python")
35+
'';
36+
};
37+
38+
# Language annotation followed by regular string
39+
regularString = /* json */ "{ \"key\": \"value\" }";
40+
multilineRegularString = /* js */ "
41+
console.log('Hello, world!');
42+
";
43+
44+
# Multiple block comments in sequence
45+
sequentialComments = /* first */ /* second */ ''
46+
some content
47+
'';
48+
49+
# Block comment with line breaks
50+
multilineBlockComment = /* this is a
51+
multiline comment */ ''
52+
content
53+
'';
54+
55+
# Mixed comment styles
56+
mixedComments = /* inline */ # line comment
57+
''
58+
content
59+
'';
60+
61+
# Language annotation in function arguments
62+
processCode = builtins.readFile (/* lua */ ''
63+
return "Hello"
64+
'');
65+
66+
# Language annotation in list
67+
scripts = [
68+
/* bash */ ''
69+
echo "Script 1"
70+
''
71+
/* python */ ''
72+
print("Script 2")
73+
''
74+
];
75+
76+
# Language annotation in attribute set
77+
languages = {
78+
lua = /* lua */ ''
79+
print("Lua")
80+
'';
81+
python = /* python */ ''
82+
print("Python")
83+
'';
84+
};
85+
86+
# Edge case: empty language annotation
87+
emptyAnnotation = /**/ ''
88+
content without annotation
89+
'';
90+
91+
# Edge case: language annotation with special characters
92+
specialChars = /* c++ */ ''
93+
#include <iostream>
94+
int main() { return 0; }
95+
'';
96+
withDot = /* .ts */ ''
97+
let x: number = 42;
98+
'';
99+
100+
# Edge case: very long language annotation
101+
longAnnotation = /* this-is-a-very-long-language-annotation-that-might-affect-line-length */ ''
102+
content
103+
'';
104+
105+
# Language annotation not followed by string
106+
object = /* json */ { key = "value"; };
107+
fn = /* foo */ x: x + 1;
108+
fnCall = /* foo */ fnName "bar";
109+
110+
111+
# Language annotation with nested expressions
112+
nestedExpr = /* bash */ ''
113+
${/* inline comment */ "echo hello"}
114+
'';
115+
116+
# Language annotation in let expression
117+
letExpr = let
118+
code = /* python */ ''
119+
print("In let")
120+
'';
121+
in code;
122+
123+
# Language annotation in function definition
124+
mkScript = lang: content: /* ${lang} */ ''
125+
${content}
126+
'';
127+
128+
# on in block
129+
expr =
130+
let
131+
in
132+
/* bash */ ''
133+
echo "Hello"
134+
'';
135+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
# Basic language annotation cases
3+
luaScript = /* lua */ ''
4+
print("Hello, world!")
5+
local x = 42
6+
'';
7+
8+
# With extra whitespace
9+
jsCode = /* javascript */ ''
10+
console.log("Hello from JS");
11+
const x = 42;
12+
'';
13+
14+
# missing whitespace after comment
15+
noSpace = /* python */ ''
16+
print("No space after comment")
17+
'';
18+
19+
# Multiple language annotations in same expression
20+
mixedCode = {
21+
lua = /* lua */ ''
22+
print("Lua code")
23+
'';
24+
python = /* python */ ''
25+
print("Python code")
26+
'';
27+
};
28+
29+
# Language annotation with indented multiline string
30+
indentedCode = {
31+
script = /* python */ ''
32+
import os
33+
def main():
34+
print("Indented Python")
35+
'';
36+
};
37+
38+
# Language annotation followed by regular string
39+
regularString = /* json */ "{ \"key\": \"value\" }";
40+
multilineRegularString = /* js */ "
41+
console.log('Hello, world!');
42+
";
43+
44+
# Multiple block comments in sequence
45+
sequentialComments = # first second
46+
''
47+
some content
48+
'';
49+
50+
# Block comment with line breaks
51+
multilineBlockComment =
52+
/*
53+
this is a
54+
multiline comment
55+
*/
56+
''
57+
content
58+
'';
59+
60+
# Mixed comment styles
61+
mixedComments = # inline line comment
62+
''
63+
content
64+
'';
65+
66+
# Language annotation in function arguments
67+
processCode = builtins.readFile (/* lua */ ''
68+
return "Hello"
69+
'');
70+
71+
# Language annotation in list
72+
scripts = [
73+
/* bash */ ''
74+
echo "Script 1"
75+
''
76+
/* python */ ''
77+
print("Script 2")
78+
''
79+
];
80+
81+
# Language annotation in attribute set
82+
languages = {
83+
lua = /* lua */ ''
84+
print("Lua")
85+
'';
86+
python = /* python */ ''
87+
print("Python")
88+
'';
89+
};
90+
91+
# Edge case: empty language annotation
92+
emptyAnnotation = ''
93+
content without annotation
94+
'';
95+
96+
# Edge case: language annotation with special characters
97+
specialChars = /* c++ */ ''
98+
#include <iostream>
99+
int main() { return 0; }
100+
'';
101+
withDot = /* .ts */ ''
102+
let x: number = 42;
103+
'';
104+
105+
# Edge case: very long language annotation
106+
longAnnotation = # this-is-a-very-long-language-annotation-that-might-affect-line-length
107+
''
108+
content
109+
'';
110+
111+
# Language annotation not followed by string
112+
object = # json
113+
{
114+
key = "value";
115+
};
116+
fn = # foo
117+
x: x + 1;
118+
fnCall = # foo
119+
fnName "bar";
120+
121+
# Language annotation with nested expressions
122+
nestedExpr = /* bash */ ''
123+
${/* inline comment */ "echo hello"}
124+
'';
125+
126+
# Language annotation in let expression
127+
letExpr =
128+
let
129+
code = /* python */ ''
130+
print("In let")
131+
'';
132+
in
133+
code;
134+
135+
# Language annotation in function definition
136+
mkScript = lang: content: /* ${lang} */ ''
137+
${content}
138+
'';
139+
140+
# on in block
141+
expr =
142+
let
143+
in
144+
/* bash */ ''
145+
echo "Hello"
146+
'';
147+
}

0 commit comments

Comments
 (0)