forked from NomicFoundation/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a unit test for the precedence expression parsers
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
mod cst_output; | ||
mod doc_examples; | ||
mod errors; | ||
mod parser; | ||
mod scanner; | ||
mod versions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use semver::Version; | ||
use slang_solidity::{kinds::RuleKind, language::Language}; | ||
|
||
#[test] | ||
fn test_precedence_expression() { | ||
let language = Language::new(Version::new(0, 8, 0)).unwrap(); | ||
|
||
let output = language.parse(RuleKind::ShiftExpression, "1 >> 2"); | ||
assert!(output.is_valid()); | ||
let output = language.parse(RuleKind::ShiftExpression, "1 + 2"); | ||
assert!(!output.is_valid()); | ||
let output = language.parse(RuleKind::ArrayTypeName, "uint[]"); | ||
assert!(output.is_valid()); | ||
|
||
// Plus prefix was removed in 0.5.0 | ||
let language = Language::new(Version::new(0, 4, 11)).unwrap(); | ||
let output = language.parse(RuleKind::PrefixExpression, "+1"); | ||
assert!(output.is_valid()); | ||
let language = Language::new(Version::new(0, 8, 0)).unwrap(); | ||
let output = language.parse(RuleKind::PrefixExpression, "+1"); | ||
assert!(!output.is_valid()); | ||
|
||
// Changed to right-associative in 0.6.0; the rule should still be valid | ||
let output = language.parse(RuleKind::ExponentiationExpression, "1 ** 2"); | ||
assert!(output.is_valid()); | ||
let language = Language::new(Version::new(0, 5, 0)).unwrap(); | ||
let output = language.parse(RuleKind::ExponentiationExpression, "1 ** 2"); | ||
assert!(output.is_valid()); | ||
} |