Skip to content

Commit

Permalink
allow leading/trailing ws in numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
dragazo committed Nov 1, 2023
1 parent ba6aecc commit d445c9c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "netsblox-vm"
version = "0.2.15"
version = "0.2.16"
edition = "2021"
license = "MIT OR Apache-2.0"
authors = ["Devin Jean <[email protected]>"]
Expand Down
1 change: 1 addition & 0 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ impl<'gc, C: CustomTypes<S>, S: System<C>> Value<'gc, C, S> {
match self {
Value::Number(x) => Ok(*x),
Value::String(x) => {
let x = x.trim();
let parsed = match x.get(..2) {
Some("0x" | "0X") => i64::from_str_radix(&x[2..], 16).ok().map(|x| x as f64),
Some("0o" | "0O") => i64::from_str_radix(&x[2..], 8).ok().map(|x| x as f64),
Expand Down
1 change: 1 addition & 0 deletions src/test/blocks/whitespace-in-numbers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<blocks app="NetsBlox 2.1.4, http://netsblox.org" version="2.1.4"><block-definition collabId="item_-1_2" s="main" type="reporter" category="custom"><header></header><code></code><translations></translations><inputs></inputs><script><block collabId="item_1" s="doDeclareVariables"><list><l>a</l></list></block><block collabId="item_0" s="doSetVar"><l>a</l><block collabId="item_3" s="reportNewList"><list></list></block></block><block collabId="item_7" s="doAddToList"><block collabId="item_20" s="reportNewList"><list><block collabId="item_9" s="reportVariadicSum"><list><block collabId="item_10" s="reportJoinWords"><list><l> 12</l></list></block><l>0</l></list></block><block collabId="item_15_1" s="reportVariadicSum"><list><block collabId="item_15_3" s="reportJoinWords"><list><l>32 </l></list></block><l>0</l></list></block><block collabId="item_17_1" s="reportVariadicSum"><list><block collabId="item_17_3" s="reportJoinWords"><list><l> 14 </l></list></block><l>0</l></list></block></list></block><block collabId="item_8" var="a"/></block><block collabId="item_15" s="doAddToList"><block collabId="item_26" s="reportNewList"><list><block collabId="item_26_1" s="reportVariadicSum"><list><block collabId="item_26_6" s="reportJoinWords"><list><l> 0x12</l></list></block><l>0</l></list></block><block collabId="item_26_2" s="reportVariadicSum"><list><block collabId="item_26_5" s="reportJoinWords"><list><l>0x32 </l></list></block><l>0</l></list></block><block collabId="item_26_3" s="reportVariadicSum"><list><block collabId="item_26_4" s="reportJoinWords"><list><l> 0x14 </l></list></block><l>0</l></list></block></list></block><block collabId="item_15_2" var="a"/></block><block collabId="item_17" s="doAddToList"><block collabId="item_30" s="reportNewList"><list><block collabId="item_30_1" s="reportVariadicSum"><list><block collabId="item_30_6" s="reportJoinWords"><list><l> 0o12</l></list></block><l>0</l></list></block><block collabId="item_30_2" s="reportVariadicSum"><list><block collabId="item_30_5" s="reportJoinWords"><list><l>0o32 </l></list></block><l>0</l></list></block><block collabId="item_30_3" s="reportVariadicSum"><list><block collabId="item_30_4" s="reportJoinWords"><list><l> 0o14 </l></list></block><l>0</l></list></block></list></block><block collabId="item_17_2" var="a"/></block><block collabId="item_34" s="doAddToList"><block collabId="item_34_1" s="reportNewList"><list><block collabId="item_34_3" s="reportVariadicSum"><list><block collabId="item_34_8" s="reportJoinWords"><list><l> 0b1001</l></list></block><l>0</l></list></block><block collabId="item_34_4" s="reportVariadicSum"><list><block collabId="item_34_7" s="reportJoinWords"><list><l>0b1011 </l></list></block><l>0</l></list></block><block collabId="item_34_5" s="reportVariadicSum"><list><block collabId="item_34_6" s="reportJoinWords"><list><l> 0b11011 </l></list></block><l>0</l></list></block></list></block><block collabId="item_34_2" var="a"/></block><block collabId="item_4" s="doReport"><block collabId="item_6" var="a"/></block></script></block-definition></blocks>
21 changes: 21 additions & 0 deletions src/test/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,27 @@ fn test_proc_list_lines() {
});
}

#[test]
fn test_proc_whitespace_in_numbers() {
let system = Rc::new(StdSystem::new_sync(BASE_URL.to_owned(), None, Config::default(), UtcOffset::UTC));
let (mut env, _) = get_running_proc(&format!(include_str!("templates/generic-static.xml"),
globals = "",
fields = "",
funcs = include_str!("blocks/whitespace-in-numbers.xml"),
methods = "",
), Settings::default(), system);

run_till_term(&mut env, |mc, _, res| {
let expect = Value::from_simple(mc, SimpleValue::from_json(json!([
[12, 32, 14],
[18, 50, 20],
[10, 26, 12],
[9, 11, 27],
])).unwrap());
assert_values_eq(&res.unwrap().0.unwrap(), &expect, 1e-5, "ws in nums");
});
}

#[test]
fn test_proc_binary_make_range() {
let system = Rc::new(StdSystem::new_sync(BASE_URL.to_owned(), None, Config::default(), UtcOffset::UTC));
Expand Down

0 comments on commit d445c9c

Please sign in to comment.