Skip to content

Commit

Permalink
Add unit tests for JavaScript semantic coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
jordins committed Jun 13, 2019
1 parent 07fe3b7 commit d6ffcd6
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 d6ffcd6

Please sign in to comment.