Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zuisong committed Apr 2, 2024
1 parent 5740c55 commit 64c9c09
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 41 deletions.
56 changes: 46 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ tracing-subscriber = { version = "0.3", optional = true }
clap = { version = "4", optional = true, features = ["derive"] }
clap_complete = { version = "4", optional = true }




[build-dependencies]

[dev-dependencies]
assert_cmd = "2"
escargot = "0.5"
pretty_assertions = { version = "1", features = ["unstable"] }

[[bin]]
Expand Down
24 changes: 3 additions & 21 deletions src/bin/chen_lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,32 +74,14 @@ fn run_file(code_file: String) -> Result<()> {
debug!(?s);
let mut f = OpenOptions::new().read(true).open(s)?;

let mut v = vec![];
f.read_to_end(&mut v)?;
let code = String::from_utf8(v)?;

let mut code = String::new();
f.read_to_string(&mut code)?;
debug!(?code);

chen_lang::run(code)?;
Ok(())
}

fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout());
}

#[cfg(test)]
mod tests {
#[test]
fn _test() {
assert_cmd::Command::new("cargo").arg("build").ok().unwrap();
}

#[test]
fn cmd_test() {
assert_cmd::Command::cargo_bin(env!("CARGO_PKG_NAME"))
.unwrap()
.args(["-h"])
.ok()
.unwrap();
}
}
17 changes: 17 additions & 0 deletions src/tests/cli_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::process::Command;

use assert_cmd::{cargo::CargoError, prelude::*};

fn command() -> Command {
let runner = escargot::CargoBuild::new()
.current_target()
.run()
.map_err(CargoError::with_cause)
.unwrap();
runner.command()
}

#[test]
fn cmd_test() {
command().args(["-h"]).ok().unwrap();
}
2 changes: 1 addition & 1 deletion src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod cli_test;
mod expression_test;
mod parse_test;
mod token_test;

#[cfg(test)]
mod tests_1 {
use pretty_assertions::assert_eq;
Expand Down
11 changes: 5 additions & 6 deletions src/tests/token_test.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#![rustfmt::skip]

use pretty_assertions::assert_eq;

use crate::Keyword::DEF;
use crate::Operator::{NotEquals, Or, Subtract};
use crate::token;
use crate::token::Keyword::{ELSE, FOR, IF, LET};
use crate::token::Operator::{ADD, Assign, Equals, LT, Mod};
use crate::token::Operator::{Assign, Equals, Mod, ADD, LT};
use crate::token::Token::{
Identifier, Int, Keyword, LBig, LParen, NewLine, Operator, RBig, RParen, String,
};
use crate::Keyword::DEF;
use crate::Operator::{NotEquals, Or, Subtract};

#[test]
fn test_parse_keyword() {
Expand Down Expand Up @@ -42,7 +40,7 @@ for i<100{
}
"#
.to_string();

#[rustfmt::skip]
assert_eq!(
token::tokenlizer(code).unwrap(),
vec![
Expand Down Expand Up @@ -90,6 +88,7 @@ println(sum)
"#
.to_string();

#[rustfmt::skip]
assert_eq!(
token::tokenlizer(code).unwrap(),
vec![
Expand Down

0 comments on commit 64c9c09

Please sign in to comment.