[fine] Tweak syntax for assertions to make me happier
This commit is contained in:
parent
758aef4db9
commit
8835d9eaf2
12 changed files with 104 additions and 25 deletions
|
|
@ -17,7 +17,7 @@ fn generate_test_for_file(path: PathBuf) -> String {
|
||||||
};
|
};
|
||||||
|
|
||||||
let line = line.trim();
|
let line = line.trim();
|
||||||
if line == "concrete:" {
|
if line == "@concrete:" {
|
||||||
let mut concrete = String::new();
|
let mut concrete = String::new();
|
||||||
while let Some(line) = lines.next() {
|
while let Some(line) = lines.next() {
|
||||||
let line = match line.strip_prefix("// | ") {
|
let line = match line.strip_prefix("// | ") {
|
||||||
|
|
@ -32,7 +32,7 @@ fn generate_test_for_file(path: PathBuf) -> String {
|
||||||
assertions.push(quote! {
|
assertions.push(quote! {
|
||||||
crate::assert_concrete(&_tree, #concrete, #display_path);
|
crate::assert_concrete(&_tree, #concrete, #display_path);
|
||||||
});
|
});
|
||||||
} else if let Some(line) = line.strip_prefix("type:") {
|
} else if let Some(line) = line.strip_prefix("@type:") {
|
||||||
let (pos, expected) = line
|
let (pos, expected) = line
|
||||||
.trim()
|
.trim()
|
||||||
.split_once(' ')
|
.split_once(' ')
|
||||||
|
|
@ -45,7 +45,7 @@ fn generate_test_for_file(path: PathBuf) -> String {
|
||||||
assertions.push(quote! {
|
assertions.push(quote! {
|
||||||
crate::assert_type_at(&_tree, &_lines, #pos, #expected, #display_path);
|
crate::assert_type_at(&_tree, &_lines, #pos, #expected, #display_path);
|
||||||
});
|
});
|
||||||
} else if let Some(line) = line.strip_prefix("type-error:") {
|
} else if let Some(line) = line.strip_prefix("@type-error:") {
|
||||||
let (pos, expected) = line
|
let (pos, expected) = line
|
||||||
.trim()
|
.trim()
|
||||||
.split_once(' ')
|
.split_once(' ')
|
||||||
|
|
|
||||||
79
fine/tests/README.md
Normal file
79
fine/tests/README.md
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
# Snapshot Tests
|
||||||
|
|
||||||
|
The `.fine` files in this directory and its descendants are processed
|
||||||
|
by `build.rs` into a series of snapshot-tests. The various test
|
||||||
|
assertions are specified by `@` directives in comments in the file.
|
||||||
|
|
||||||
|
e.g., a test might look like this:
|
||||||
|
|
||||||
|
```fine
|
||||||
|
// @concrete:
|
||||||
|
// | File
|
||||||
|
// | ExpressionStatement
|
||||||
|
// | BinaryExpression
|
||||||
|
// | BinaryExpression
|
||||||
|
// | LiteralExpression
|
||||||
|
// | Number:'"1"'
|
||||||
|
// | Star:'"*"'
|
||||||
|
// | LiteralExpression
|
||||||
|
// | Number:'"2"'
|
||||||
|
// | Plus:'"+"'
|
||||||
|
// | BinaryExpression
|
||||||
|
// | UnaryExpression
|
||||||
|
// | Minus:'"-"'
|
||||||
|
// | LiteralExpression
|
||||||
|
// | Number:'"3"'
|
||||||
|
// | Star:'"*"'
|
||||||
|
// | LiteralExpression
|
||||||
|
// | Number:'"4"'
|
||||||
|
// | Semicolon:'";"'
|
||||||
|
//
|
||||||
|
1 * 2 + -3 * 4;
|
||||||
|
|
||||||
|
// @type: 532 f64
|
||||||
|
```
|
||||||
|
|
||||||
|
## Assertions
|
||||||
|
|
||||||
|
The various assertions are as follows:
|
||||||
|
|
||||||
|
- The `// @concrete:` assertion says that the following lines
|
||||||
|
(prefixed with `// | `, as above) describe the concrete syntax tree
|
||||||
|
of the file after parsing.
|
||||||
|
|
||||||
|
e.g.:
|
||||||
|
|
||||||
|
```fine
|
||||||
|
// @concrete:
|
||||||
|
// | File
|
||||||
|
// | ExpressionStatement
|
||||||
|
// | LiteralExpression
|
||||||
|
// | String:'"\"Hello world\""'
|
||||||
|
// | Semicolon:'";"'
|
||||||
|
//
|
||||||
|
"Hello world";
|
||||||
|
```
|
||||||
|
|
||||||
|
- The `// @type:` assertion says that the type of the tree at the
|
||||||
|
given point will match the given type. `@type` assertions usually go
|
||||||
|
after the contents of the file to make the probe points more stable
|
||||||
|
in the face of new assertions and whatnot.
|
||||||
|
|
||||||
|
e.g.:
|
||||||
|
|
||||||
|
```fine
|
||||||
|
"Hello world!"
|
||||||
|
// @type: 2 string
|
||||||
|
```
|
||||||
|
|
||||||
|
- The `// @type-error:` assertion says that the type of the tree at
|
||||||
|
the given point should be an error, and that the error message
|
||||||
|
provided should be among the generated errors. (Like `@type`, these
|
||||||
|
usually go after the code, for stability.)
|
||||||
|
|
||||||
|
e.g.:
|
||||||
|
|
||||||
|
```fine
|
||||||
|
- "twenty five";
|
||||||
|
// @type-error: 0 cannot apply unary operator '-' to value of type string
|
||||||
|
```
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// concrete:
|
// @concrete:
|
||||||
// | File
|
// | File
|
||||||
// | ExpressionStatement
|
// | ExpressionStatement
|
||||||
// | BinaryExpression
|
// | BinaryExpression
|
||||||
|
|
@ -21,4 +21,4 @@
|
||||||
//
|
//
|
||||||
1 * 2 + -3 * 4;
|
1 * 2 + -3 * 4;
|
||||||
|
|
||||||
// type: 532 f64
|
// @type: 532 f64
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// concrete:
|
// @concrete:
|
||||||
// | File
|
// | File
|
||||||
// | ExpressionStatement
|
// | ExpressionStatement
|
||||||
// | BinaryExpression
|
// | BinaryExpression
|
||||||
|
|
@ -21,4 +21,4 @@
|
||||||
//
|
//
|
||||||
true and false or false and !true;
|
true and false or false and !true;
|
||||||
|
|
||||||
// type: 549 bool
|
// @type: 549 bool
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// concrete:
|
// @concrete:
|
||||||
// | File
|
// | File
|
||||||
// | IfStatement
|
// | IfStatement
|
||||||
// | ConditionalExpression
|
// | ConditionalExpression
|
||||||
|
|
@ -27,18 +27,18 @@ if true { "discarded"; 23 } else { 45 }
|
||||||
|
|
||||||
// Here come some type probes!
|
// Here come some type probes!
|
||||||
// (type of the condition)
|
// (type of the condition)
|
||||||
// type: 667 bool
|
// @type: 667 bool
|
||||||
//
|
//
|
||||||
// (the discarded expression)
|
// (the discarded expression)
|
||||||
// type: 674 string
|
// @type: 674 string
|
||||||
//
|
//
|
||||||
// (the "then" clause)
|
// (the "then" clause)
|
||||||
// type: 686 f64
|
// @type: 686 f64
|
||||||
// type: 689 f64
|
// @type: 689 f64
|
||||||
//
|
//
|
||||||
// (the "else" clause)
|
// (the "else" clause)
|
||||||
// type: 696 f64
|
// @type: 696 f64
|
||||||
// type: 699 f64
|
// @type: 699 f64
|
||||||
//
|
//
|
||||||
// (the overall expression)
|
// (the overall expression)
|
||||||
// type: 664 f64
|
// @type: 664 f64
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
112 - "twenty five";
|
112 - "twenty five";
|
||||||
"twenty five" - 112;
|
"twenty five" - 112;
|
||||||
// type-error: 4 cannot apply binary operator '-' to expressions of type 'f64' (on the left) and 'string' (on the right)
|
// @type-error: 4 cannot apply binary operator '-' to expressions of type 'f64' (on the left) and 'string' (on the right)
|
||||||
// type-error: 35 cannot apply binary operator '-' to expressions of type 'string' (on the left) and 'f64' (on the right)
|
// @type-error: 35 cannot apply binary operator '-' to expressions of type 'string' (on the left) and 'f64' (on the right)
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
if true { "blarg" } else { 23 }
|
if true { "blarg" } else { 23 }
|
||||||
// type-error: 0 the type of the `then` branch (string) must match the type of the `else` branch (f64)
|
// @type-error: 0 the type of the `then` branch (string) must match the type of the `else` branch (f64)
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
if 23 { "what" } else { "the" }
|
if 23 { "what" } else { "the" }
|
||||||
// type-error: 0 conditions must yield a boolean
|
// @type-error: 0 conditions must yield a boolean
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
if (if false { true }) { 32 } else { 23 }
|
if (if false { true }) { 32 } else { 23 }
|
||||||
// type-error: 4 the type of the `then` branch (bool) must match the type of the `else` branch (())
|
// @type-error: 4 the type of the `then` branch (bool) must match the type of the `else` branch (())
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
- "twenty five";
|
- "twenty five";
|
||||||
// type-error: 0 cannot apply unary operator '-' to value of type string
|
// @type-error: 0 cannot apply unary operator '-' to value of type string
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// concrete:
|
// @concrete:
|
||||||
// | File
|
// | File
|
||||||
// | ExpressionStatement
|
// | ExpressionStatement
|
||||||
// | LiteralExpression
|
// | LiteralExpression
|
||||||
|
|
@ -7,4 +7,4 @@
|
||||||
|
|
||||||
42;
|
42;
|
||||||
|
|
||||||
// type: 129 f64
|
// @type: 129 f64
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// concrete:
|
// @concrete:
|
||||||
// | File
|
// | File
|
||||||
// | ExpressionStatement
|
// | ExpressionStatement
|
||||||
// | BinaryExpression
|
// | BinaryExpression
|
||||||
|
|
@ -11,4 +11,4 @@
|
||||||
//
|
//
|
||||||
"Hello " + 'world!';
|
"Hello " + 'world!';
|
||||||
|
|
||||||
// type: 261 string
|
// @type: 261 string
|
||||||
Loading…
Add table
Add a link
Reference in a new issue