Skip to content
Myr

Move tokenize to new file

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent 13986b1 · Browse files · 4 files+64 added−63 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+64 added−63 removed

  • other:+64 added−63 removed

4 files+64 added−63 removed

modified:src/benchmark.rs+1 added-1 removed
7 unmodified lines
8use crate::benchmark_result::BenchmarkResult;9use crate::command::Command;10use crate::format::{format_duration, format_duration_unit};11use crate::internal::{max, min, MIN_EXECUTION_TIME};12use crate::progress_bar::get_progress_bar;12use crate::options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};13use crate::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};14use crate::progress_bar::get_progress_bar;15use crate::shell::execute_and_time;16use crate::timer::wallclocktimer::WallClockTimer;17use crate::timer::{TimerStart, TimerStop};18use crate::units::Second;
467 unmodified lines
modified:src/internal.rs-61 removed
162 unmodified lines
163 let annotated_results = compute_relative_speed(&results);164165 assert!(annotated_results.is_none());166}167168pub fn tokenize(values: &str) -> Vec<String> {169 let mut tokens = vec![];170 let mut buf = String::new();171172 let mut iter = values.chars();173 while let Some(c) = iter.next() {174 match c {175 '\\' => match iter.next() {176 Some(c2 @ ',') | Some(c2 @ '\\') => {177 buf.push(c2);178 }179 Some(c2) => {180 buf.push('\\');181 buf.push(c2);182 }183 None => buf.push('\\'),184 },185 ',' => {186 tokens.push(buf);187 buf = String::new();188 }189 _ => {190 buf.push(c);191 }192 };193 }194195 tokens.push(buf);196197 tokens198}199200#[test]201fn test_tokenize_single_value() {202 assert_eq!(tokenize(r""), vec![""]);203 assert_eq!(tokenize(r"foo"), vec!["foo"]);204 assert_eq!(tokenize(r" "), vec![" "]);205 assert_eq!(tokenize(r"hello\, world!"), vec!["hello, world!"]);206 assert_eq!(tokenize(r"\,"), vec![","]);207 assert_eq!(tokenize(r"\,\,\,"), vec![",,,"]);208 assert_eq!(tokenize(r"\n"), vec![r"\n"]);209 assert_eq!(tokenize(r"\\"), vec![r"\"]);210 assert_eq!(tokenize(r"\\\,"), vec![r"\,"]);211}212213#[test]214fn test_tokenize_multiple_values() {215 assert_eq!(tokenize(r"foo,bar,baz"), vec!["foo", "bar", "baz"]);216 assert_eq!(tokenize(r"hello world,foo"), vec!["hello world", "foo"]);217218 assert_eq!(tokenize(r"hello\,world!,baz"), vec!["hello,world!", "baz"]);219}220221#[test]222fn test_tokenize_empty_values() {223 assert_eq!(tokenize(r"foo,,bar"), vec!["foo", "", "bar"]);224 assert_eq!(tokenize(r",bar"), vec!["", "bar"]);225 assert_eq!(tokenize(r"bar,"), vec!["bar", ""]);226 assert_eq!(tokenize(r",,"), vec!["", "", ""]);227}
modified:src/main.rs+3 added-1 removed
19 unmodified lines
20pub mod parameter_range;21pub mod progress_bar;22pub mod shell;23pub mod timer;24pub mod tokenize;25pub mod types;26pub mod units;27pub mod warnings;28
1 unmodified line
30use benchmark::{mean_shell_spawning_time, run_benchmark};31use command::Command;32use error::OptionsError;33use export::{ExportManager, ExportType};33use internal::{tokenize, write_benchmark_comparison};34use internal::write_benchmark_comparison;35use options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};36use parameter_range::get_parameterized_commands;37use tokenize::tokenize;38use types::ParameterValue;39use units::Unit;4041/// Print error message to stderr and terminate
384 unmodified lines
added:src/tokenize.rs+60 added
1pub fn tokenize(values: &str) -> Vec<String> {2 let mut tokens = vec![];3 let mut buf = String::new();45 let mut iter = values.chars();6 while let Some(c) = iter.next() {7 match c {8 '\\' => match iter.next() {9 Some(c2 @ ',') | Some(c2 @ '\\') => {10 buf.push(c2);11 }12 Some(c2) => {13 buf.push('\\');14 buf.push(c2);15 }16 None => buf.push('\\'),17 },18 ',' => {19 tokens.push(buf);20 buf = String::new();21 }22 _ => {23 buf.push(c);24 }25 };26 }2728 tokens.push(buf);2930 tokens31}3233#[test]34fn test_tokenize_single_value() {35 assert_eq!(tokenize(r""), vec![""]);36 assert_eq!(tokenize(r"foo"), vec!["foo"]);37 assert_eq!(tokenize(r" "), vec![" "]);38 assert_eq!(tokenize(r"hello\, world!"), vec!["hello, world!"]);39 assert_eq!(tokenize(r"\,"), vec![","]);40 assert_eq!(tokenize(r"\,\,\,"), vec![",,,"]);41 assert_eq!(tokenize(r"\n"), vec![r"\n"]);42 assert_eq!(tokenize(r"\\"), vec![r"\"]);43 assert_eq!(tokenize(r"\\\,"), vec![r"\,"]);44}4546#[test]47fn test_tokenize_multiple_values() {48 assert_eq!(tokenize(r"foo,bar,baz"), vec!["foo", "bar", "baz"]);49 assert_eq!(tokenize(r"hello world,foo"), vec!["hello world", "foo"]);5051 assert_eq!(tokenize(r"hello\,world!,baz"), vec!["hello,world!", "baz"]);52}5354#[test]55fn test_tokenize_empty_values() {56 assert_eq!(tokenize(r"foo,,bar"), vec!["foo", "", "bar"]);57 assert_eq!(tokenize(r",bar"), vec!["", "bar"]);58 assert_eq!(tokenize(r"bar,"), vec!["bar", ""]);59 assert_eq!(tokenize(r",,"), vec!["", "", ""]);60}