Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dsc_lib/src/functions/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ mod tests {
assert_eq!(result, 123);
}

#[test]
fn float() {
let mut parser = Statement::new().unwrap();
let err = parser.parse_and_execute("[int(1.2)]", &Context::new()).unwrap_err();
assert!(matches!(err, DscError::IntegerConversion(_)));
}

#[test]
fn nested() {
let mut parser = Statement::new().unwrap();
Expand Down
14 changes: 14 additions & 0 deletions tree-sitter-dscexpression/corpus/invalid_expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,17 @@ Incomplete expression
(function
(functionName)))
(MISSING "]"))

=====
Invalid float argument
=====
[myFunction(a.1)]
---

(statement
(expression
(function
(functionName)
(ERROR
(functionName)
(memberName)))))
26 changes: 26 additions & 0 deletions tree-sitter-dscexpression/corpus/valid_expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,29 @@ Nested dot-notation
(memberName)))))
(memberAccess
(memberName))))

=====
Float input
=====
[myFunction(1234.5678)]
---

(statement
(expression
(function
(functionName)
(arguments
(number)))))

=====
Quotes float input
=====
[myFunction('1234.5678')]
---

(statement
(expression
(function
(functionName)
(arguments
(string)))))
2 changes: 1 addition & 1 deletion tree-sitter-dscexpression/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = grammar({
_quotedString: $ => seq('\'', $.string, '\''),
// ARM strings do not allow to contain single-quote characters
string: $ => /[^']*/,
number: $ => /-?\d+/,
number: $ => /[+-]?([0-9]*[.])?[0-9]+/,
boolean: $ => choice('true', 'false'),

memberAccess: $ => seq('.', $.memberName, repeat(seq('.', $.memberName))),
Expand Down