Changeset - 392c59600687
[Not reviewed]
0 3 0
mh - 4 years ago 2021-05-31 11:37:55
contact@maxhenger.nl
Test non-ascii string literals and recursion
3 files changed with 57 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/protocol/input_source.rs
Show inline comments
 
@@ -168,7 +168,6 @@ impl InputSource {
 
        }
 

	
 
        lookup.push(self.input.len() as u32 + 1); // for lookup_line_end, intentionally adding one character
 
        debug_assert_eq!(self.line as usize + 2, lookup.len(), "remove me: i am a testing assert and sometimes invalid");
 

	
 
        // Return created lookup
 
        drop(lookup);
src/protocol/tests/eval_calls.rs
Show inline comments
 
@@ -27,6 +27,58 @@ fn test_function_call() {
 
    });
 
}
 

	
 
#[test]
 
fn test_recursion() {
 
    // Single-chain
 
    Tester::new_single_source_expect_ok("factorial", "
 
    func horribly_slow_factorial(u32 term) -> u32 {
 
        if (term <= 0) { return 1; }
 

	
 
        return term * horribly_slow_factorial(term - 1);
 
    }
 
    func foo() -> u32 {
 
        return horribly_slow_factorial(10);
 
    }
 
    ").for_function("foo", |f| {
 
        f.call_ok(Some(Value::UInt32(3628800)));
 
    });
 

	
 
    // Multi-chain horribleness
 
    Tester::new_single_source_expect_ok("fibonacci", "
 
    func horribly_slow_fibo(u32 term) -> u32 {
 
        if (term <= 1) {
 
            return 1;
 
        }
 
        return horribly_slow_fibo(term - 2) + horribly_slow_fibo(term - 1);
 
    }
 
    func foo() -> u32 {
 
        return horribly_slow_fibo(10);
 
    }").for_function("foo", |f| {
 
        f.call_ok(Some(Value::UInt32(89)));
 
    });
 

	
 
    // Mutual recursion (in a contrived fashion, ofcourse)
 
    Tester::new_single_source_expect_ok("mutual recursion", "
 
    func collatz_even(u32 iter, u32 value) -> u32 {
 
        value = value / 2;
 
        if (value % 2 == 0) return collatz_even(iter + 1, value);
 
        else                return collatz_odd(iter + 1, value);
 
    }
 
    func collatz_odd(u32 iter, u32 value) -> u32 {
 
        if (value <= 1) return iter;
 

	
 
        value = 3 * value + 1;
 
        if (value % 2 == 0) return collatz_even(iter + 1, value);
 
        else                return collatz_odd(iter + 1, value);
 
    }
 
    func foo() -> u32 {
 
        return collatz_odd(1, 19);
 
    }
 
    ").for_function("foo", |f| {
 
        f.call_ok(Some(Value::UInt32(21)));
 
    });
 
}
 

	
 
#[test]
 
fn test_empty_blocks() {
 
    // Yes this is silly, but I managed to make this a bug before
src/protocol/tests/parser_literals.rs
Show inline comments
 
@@ -62,4 +62,9 @@ fn test_string_literals() {
 
    Tester::new_single_source_expect_err("invalid escaped character", "
 
        func test() -> string { return \"\\y\"; }
 
    ").error(|e| { e.assert_msg_has(0, "unsupported escape character 'y'"); });
 

	
 
    // Note sure if this should always be in here...
 
    Tester::new_single_source_expect_err("non-ASCII string", "
 
        func test() -> string { return \"💧\"; }
 
    ").error(|e| { e.assert_msg_has(0, "non-ASCII character in string literal"); });
 
}
 
\ No newline at end of file
0 comments (0 inline, 0 general)