From 2d2b5625e04a466362c9a4afb05e2f559c4fb4b0 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 21 Jun 2021 15:13:25 -0400 Subject: feat(repl): Type stripping in the REPL (#10934) --- cli/tests/integration_tests.rs | 84 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 6 deletions(-) (limited to 'cli/tests/integration_tests.rs') diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index c50d80323..081ea40e5 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -2022,9 +2022,9 @@ mod integration { let mut output = String::new(); master.read_to_string(&mut output).unwrap(); - assert!(output.contains("Unexpected token ')'")); - assert!(output.contains("Unexpected token ']'")); - assert!(output.contains("Unexpected token '}'")); + assert!(output.contains("Unexpected token `)`")); + assert!(output.contains("Unexpected token `]`")); + assert!(output.contains("Unexpected token `}`")); fork.wait().unwrap(); } else { @@ -2231,6 +2231,59 @@ mod integration { assert!(err.is_empty()); } + #[test] + fn typescript() { + let (out, err) = util::run_and_collect_output( + true, + "repl", + Some(vec![ + "function add(a: number, b: number) { return a + b }", + "const result: number = add(1, 2) as number;", + "result", + ]), + Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]), + false, + ); + assert!(out.ends_with("undefined\nundefined\n3\n")); + assert!(err.is_empty()); + } + + #[test] + fn typescript_declarations() { + let (out, err) = util::run_and_collect_output( + true, + "repl", + Some(vec![ + "namespace Test { export enum Values { A, B, C } }", + "Test.Values.A", + "Test.Values.C", + "interface MyInterface { prop: string; }", + "type MyTypeAlias = string;", + ]), + Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]), + false, + ); + assert!(out.ends_with("undefined\n0\n2\nundefined\nundefined\n")); + assert!(err.is_empty()); + } + + #[test] + fn typescript_decorators() { + let (out, err) = util::run_and_collect_output( + true, + "repl", + Some(vec![ + "function dec(target) { target.prototype.test = () => 2; }", + "@dec class Test {}", + "new Test().test()", + ]), + Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]), + false, + ); + assert!(out.ends_with("undefined\nundefined\n2\n")); + assert!(err.is_empty()); + } + #[test] fn eof() { let (out, err) = util::run_and_collect_output( @@ -2362,11 +2415,30 @@ mod integration { let (out, err) = util::run_and_collect_output( true, "repl", - Some(vec!["syntax error"]), - None, + Some(vec![ + "syntax error", + "2", // ensure it keeps accepting input after + ]), + Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]), + false, + ); + assert!( + out.ends_with("parse error: Expected ';', '}' or at 1:7\n2\n") + ); + assert!(err.is_empty()); + } + + #[test] + fn syntax_error_jsx() { + // JSX is not supported in the REPL + let (out, err) = util::run_and_collect_output( + true, + "repl", + Some(vec!["const element =
;"]), + Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]), false, ); - assert!(out.contains("Unexpected identifier")); + assert!(out.contains("Unexpected token `>`")); assert!(err.is_empty()); } -- cgit v1.2.3