Skip to content

Commit

Permalink
Add a unit test for the precedence expression parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Dec 8, 2023
1 parent 9f0add6 commit 0296bef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/solidity/outputs/cargo/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
mod cst_output;
mod doc_examples;
mod errors;
mod parser;
mod scanner;
mod versions;
29 changes: 29 additions & 0 deletions crates/solidity/outputs/cargo/tests/src/parser/mod.rs
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());
}

0 comments on commit 0296bef

Please sign in to comment.