Skip to content

Commit

Permalink
Merge pull request #129 from jordins/master
Browse files Browse the repository at this point in the history
Add unit tests for JavaScript semantic coloring
  • Loading branch information
jonhoo authored Jun 13, 2019
2 parents 07fe3b7 + d6ffcd6 commit fca4745
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/flamegraph/color/palettes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,57 @@ pub(super) mod wakeup {
BasicPalette::Aqua
}
}

#[cfg(test)]
mod tests {
use crate::flamegraph::color::BasicPalette;

struct TestData {
input: String,
output: BasicPalette,
}

#[test]
fn js_returns_correct() {
use super::js;

let test_data = [
TestData {
input: String::from(" "),
output: BasicPalette::Green,
},
TestData {
input: String::from("something_[k]"),
output: BasicPalette::Orange,
},
TestData {
input: String::from("something/_[j]"),
output: BasicPalette::Green,
},
TestData {
input: String::from("something_[j]"),
output: BasicPalette::Aqua,
},
TestData {
input: String::from("some::thing"),
output: BasicPalette::Yellow,
},
TestData {
input: String::from("some:thing"),
output: BasicPalette::Aqua,
},
TestData {
input: String::from("some/ai.js"),
output: BasicPalette::Green,
},
TestData {
input: String::from("someai.js"),
output: BasicPalette::Red,
},
];
for elem in test_data.iter() {
let result = js::resolve(&elem.input);
assert_eq!(result, elem.output);
}
}
}

0 comments on commit fca4745

Please sign in to comment.