Skip to content

Commit

Permalink
Add tests & fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sozysozbot committed Jul 20, 2020
1 parent c6b1954 commit ae3eaf5
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,19 @@ fn compile_statement(
);
env.shu1zhi1_reference = vec![];
}
parse::Statement::Define { decl: parse::DeclareStatement {
how_many_variables,
type_,
data_arr,
}, idents } => {
parse::Statement::Define {
decl:
parse::DeclareStatement {
how_many_variables,
type_,
data_arr,
},
idents,
} => {
// It is possible to have three conflicting information on the number of variables declared.
// Let's say we have `吾有三數。曰三。曰九。名之曰「庚」。曰「辛」。曰「壬」。曰「癸」。書之。`
// Then `how_many_variables` is `3`, `type_` is `Type::Shu4`, `data_arr` is `vec![3, 9]` and `idents` are the idents.
// This compiles to
// This compiles to
// ```
// var 庚 = 3;
// var 辛 = 9;
Expand Down Expand Up @@ -123,7 +127,7 @@ fn compile_statement(
// `data_arr` is truncated or padded so that its length matches `how_many_variables`,
// `idents` fills the open spots,
// and remaining spots (if any) will be accessible by 書之 .

let mut new_shu1zhi1 = vec![];
for i in 0..*how_many_variables {
match idents.get(i) {
Expand All @@ -147,10 +151,8 @@ fn compile_statement(
));
}
}

}
env.shu1zhi1_reference = new_shu1zhi1;

}
parse::Statement::ForEnum { num, statements } => {
let mut inner = String::new();
Expand Down
26 changes: 26 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ mod tests {
fn test006() {
test("test006")
}
#[test]
fn test007() {
test("test007")
}
#[test]
fn test008() {
test("test008")
}
#[test]
fn test009() {
test("test009")
}
#[test]
fn test010() {
test("test010")
}

#[test]
fn test011() {
test("test011")
}

#[test]
fn test012() {
test("test012")
}
}

use std::collections::HashMap;
Expand Down
4 changes: 3 additions & 1 deletion src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ fn interpret_intnum(num: &lex::IntNum) -> i64 {
&[lex::IntNumKeywords::Qi1] => 7,
&[lex::IntNumKeywords::Ba1] => 8,
&[lex::IntNumKeywords::Jiu3] => 9,
_ => unimplemented!(),
&[lex::IntNumKeywords::Shi2] => 10,
&[lex::IntNumKeywords::Qian1] => 1000,
_ => unimplemented!("parsing integer"),
}
}

Expand Down
9 changes: 9 additions & 0 deletions test009.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main() {
let JIA3 = 3.0;
let mut _rand1 = 0.0;
while _rand1 < JIA3 {
let _ans1 = "問天地好在。";
println!("{}", _ans1);
_rand1 += 1.0;
}
}
4 changes: 4 additions & 0 deletions test009.wy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
吾有一數。曰三。名之曰「甲」。
為是「甲」遍。
 吾有一言。曰「「問天地好在。」」。書之。
云云。
10 changes: 10 additions & 0 deletions test010.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
for _ in 0..5 {
let _ans1 = "問天地好在。";
println!("{}", _ans1);
}
for _ in 0..10 {
let _ans1 = "問天地好在。";
println!("{}", _ans1);
}
}
8 changes: 8 additions & 0 deletions test010.wy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
為是五遍。
 吾有一言。曰「「問天地好在。」」。書之。
云云。

為是十遍。
 吾有一言。曰「「問天地好在。」」。書之。
云云。

10 changes: 10 additions & 0 deletions test011.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
for _ in 0..5 {
let _ans1 = "問天地好在。";
println!("{}", _ans1);
}
for _ in 0..1000 {
let _ans1 = "問天地好在。";
println!("{}", _ans1);
}
}
7 changes: 7 additions & 0 deletions test011.wy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
為是五遍。
 吾有一言。曰「「問天地好在。」」。書之。
云云。

為是千遍。
 吾有一言。曰「「問天地好在。」」。書之。
云云。
5 changes: 5 additions & 0 deletions test012.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
let JIA3 = 3.0;
let _ans1 = "問天地好在。";
println!("{}", _ans1);
}
2 changes: 2 additions & 0 deletions test012.wy
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
吾有一數。曰三。名之曰「甲」。
吾有一言。曰「「問天地好在。」」。書之。

0 comments on commit ae3eaf5

Please sign in to comment.