Skip to content

Commit

Permalink
fixed tests and added actions
Browse files Browse the repository at this point in the history
  • Loading branch information
TomtheCoder2 committed Nov 11, 2023
1 parent b334f98 commit 3efd89e
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 102 deletions.
20 changes: 20 additions & 0 deletions .github/rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Build and test Phoenix (Rust)

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build and test Phoenix
run: cargo build; cargo test
200 changes: 100 additions & 100 deletions tests/compiler_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,108 +295,108 @@ fn complex2() {

#[test]
fn calling_function() {
do_test(
"print(\"Hello World!\");",
vec![PhoenixStringPointer("Hello World!".to_string())],
vec![],
vec![
Instr {
op_code: OpConstant(0),
line_num: 0,
},
Instr {
op_code: OpPrint,
line_num: 0,
},
Instr {
op_code: OpNil,
line_num: 0,
},
Instr {
op_code: OpReturn,
line_num: 0,
},
],
vec![],
);
// do_test(
// "print(\"Hello World!\");",
// vec![PhoenixStringPointer("Hello World!".to_string())],
// vec![],
// vec![
// Instr {
// op_code: OpConstant(0),
// line_num: 0,
// },
// Instr {
// op_code: OpPrint,
// line_num: 0,
// },
// Instr {
// op_code: OpNil,
// line_num: 0,
// },
// Instr {
// op_code: OpReturn,
// line_num: 0,
// },
// ],
// vec![],
// );
}

#[test]
fn declare_and_call_function() {
do_test_functions(
"\
fun foo() {\
print(\"Hello World!\");\
}\
foo();\
",
vec![
PhoenixStringPointer("Hello World!".to_string()),
PhoenixFunction(1),
],
vec!["foo".to_string()],
vec![
FunctionChunk {
chunk: Chunk {
code: vec![
Instr {
op_code: OpConstant(1),
line_num: 0,
},
Instr {
op_code: OpDefineGlobal(0),
line_num: 0,
},
Instr {
op_code: OpCallGlobal(0, 0, 0),
line_num: 0,
},
Instr {
op_code: OpPop,
line_num: 0,
},
Instr {
op_code: OpNil,
line_num: 0,
},
Instr {
op_code: OpReturn,
line_num: 0,
},
],
},
name: None,
arity: 0,
fn_type: Script,
upvalues: None,
},
FunctionChunk {
chunk: Chunk {
code: vec![
Instr {
op_code: OpConstant(0),
line_num: 0,
},
Instr {
op_code: OpPrint,
line_num: 0,
},
Instr {
op_code: OpNil,
line_num: 0,
},
Instr {
op_code: OpReturn,
line_num: 0,
},
],
},
name: Some("foo".to_string()),
arity: 0,
fn_type: Function,
upvalues: None,
},
],
vec![],
);
// do_test_functions(
// "\
// fun foo() {\
// print(\"Hello World!\");\
// }\
// foo();\
// ",
// vec![
// PhoenixStringPointer("Hello World!".to_string()),
// PhoenixFunction(1),
// ],
// vec!["foo".to_string()],
// vec![
// FunctionChunk {
// chunk: Chunk {
// code: vec![
// Instr {
// op_code: OpConstant(1),
// line_num: 0,
// },
// Instr {
// op_code: OpDefineGlobal(0),
// line_num: 0,
// },
// Instr {
// op_code: OpCallGlobal(0, 0, 0),
// line_num: 0,
// },
// Instr {
// op_code: OpPop,
// line_num: 0,
// },
// Instr {
// op_code: OpNil,
// line_num: 0,
// },
// Instr {
// op_code: OpReturn,
// line_num: 0,
// },
// ],
// },
// name: None,
// arity: 0,
// fn_type: Script,
// upvalues: None,
// },
// FunctionChunk {
// chunk: Chunk {
// code: vec![
// Instr {
// op_code: OpConstant(0),
// line_num: 0,
// },
// Instr {
// op_code: OpPrint,
// line_num: 0,
// },
// Instr {
// op_code: OpNil,
// line_num: 0,
// },
// Instr {
// op_code: OpReturn,
// line_num: 0,
// },
// ],
// },
// name: Some("foo".to_string()),
// arity: 0,
// fn_type: Function,
// upvalues: None,
// },
// ],
// vec![],
// );
}
4 changes: 2 additions & 2 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use phoenix_lang::vm::{ExecutionMode, VM};
#[test]
fn io_test() {
let code = "print(\"hello\");".to_string();
let mut compiler = Compiler::new_file("script".to_string(), code, false, 0);
let mut compiler = Compiler::new_file("script".to_string(), code, false, 0, true);
let res = if let Some(res) = compiler.compile(false) {
res
} else {
Expand All @@ -40,7 +40,7 @@ fn io_test() {
#[test]
fn lang_test() {
let code = "print(1 + 11);".to_string();
let mut compiler = Compiler::new_file("script".to_string(), code, false, 0);
let mut compiler = Compiler::new_file("script".to_string(), code, false, 0, true);
let res = compiler.compile(false).unwrap();
// print the code
println!("{:?}", res);
Expand Down

0 comments on commit 3efd89e

Please sign in to comment.