Skip to content

Commit

Permalink
Merge pull request #15 from mnbjhu/testing_and_or_refactoring
Browse files Browse the repository at this point in the history
testing
  • Loading branch information
mnbjhu authored Aug 6, 2024
2 parents 87f7a46 + b6958b8 commit a68318d
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 1 deletion.
21 changes: 20 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
permissions:
contents: write
issues: write
checks: write
pull-requests: write

on:
pull_request:
push:
Expand Down Expand Up @@ -50,5 +56,18 @@ jobs:
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
args: --tests -- -D warnings
name: Clippy Output

# clippy:
# name: Clippy
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: dtolnay/rust-toolchain@stable
# with:
# components: clippy
# - uses: auguwu/clippy-action@1.4.0
# with:
# token: ${{secrets.GITHUB_TOKEN}}
# args: --cfg test -D warnings
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
name = "another-giblang-impl"
version = "0.1.0"
edition = "2021"
description = "Another implementation of the Giblang programming language"
repository = "https:://github.com/mnbjhu/another-giblang-impl"


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -11,3 +14,5 @@ clap = { version = "4.5.3", features = ["derive"] }
chumsky = "1.0.0-alpha.7"
ptree = "0.4.0"
glob = "0.3.1"

[lints.clippy]
77 changes: 77 additions & 0 deletions src/check/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,80 @@ impl<'file> CheckState<'file> {
todo!()
}
}

#[cfg(test)]
mod tests {
use crate::{
check::{state::CheckState, ty::tests::parse_ty},
project::Project,
ty::Generic,
};

fn test_project() -> Project {
let mut project = Project::from(
r#"struct Foo
struct Bar
struct Baz[T]
trait Magic {
fn magic(): Self
}
trait Epic {
fn epic(): Self
}
trait Strange [T] {
fn strange(): T
}
impl Magic for Foo
impl Magic for Bar
impl Epic for Bar
impl Strange[T] for Baz[T]"#,
);
project.resolve();
project
}

fn test_state(project: &Project) -> CheckState {
let file_data = project.get_file(0).unwrap();
CheckState::from_file(file_data, project)
}

#[test]
fn variables() {
let project = test_project();
let mut state = test_state(&project);
state.enter_scope();
state.insert_variable("foo".to_string(), parse_ty(&project, "Foo"));
assert_eq!(
*state.get_variable("foo").unwrap(),
parse_ty(&project, "Foo")
);
state.exit_scope();
assert!(state.get_variable("foo").is_none());
}

#[test]
fn generics() {
let project = test_project();
let mut state = test_state(&project);
state.enter_scope();
state.insert_generic(
"T".to_string(),
Generic {
name: "T".to_string(),
..Default::default()
},
);
assert_eq!(
*state.get_generic("T").unwrap(),
Generic {
name: "T".to_string(),
..Default::default()
}
);
state.exit_scope();
assert!(state.get_generic("T").is_none());
}
}
10 changes: 10 additions & 0 deletions src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ pub struct Generic {
pub super_: Box<Ty>,
}

impl Default for Generic {
fn default() -> Self {
Self {
name: "".to_string(),
variance: Variance::Invariant,
super_: Box::new(Ty::Any),
}
}
}

impl Generic {
pub fn get_name(&self, project: &Project) -> String {
format!(
Expand Down

0 comments on commit a68318d

Please sign in to comment.