Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
16 changes: 15 additions & 1 deletion dsc_lib/src/functions/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ 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 incomplete_float() {
let mut parser = Statement::new().unwrap();
let err = parser.parse_and_execute("[int(.2)]", &Context::new()).unwrap_err();
assert!(matches!(err, DscError::IntegerConversion(_)));
}

#[test]
fn nested() {
let mut parser = Statement::new().unwrap();
Expand All @@ -77,7 +91,7 @@ mod tests {
#[test]
fn error() {
let mut parser = Statement::new().unwrap();
let err = parser.parse_and_execute("[int('foo')]", &Context::new()).unwrap_err();
let err = parser.parse_and_execute("[int('foo.1')]", &Context::new()).unwrap_err();
assert!(matches!(err, DscError::FunctionArg(_, _)));
}
}
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: $ => /-?(\d*[.])?\d+/,
boolean: $ => choice('true', 'false'),

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