Skip to content

Commit 8685d36

Browse files
committed
ported almost all methods, start adding tests
1 parent db0c6e3 commit 8685d36

File tree

3 files changed

+1247
-145
lines changed

3 files changed

+1247
-145
lines changed

src/lib.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1+
// Copyright (C) 2020 Quentin M. Kniep <[email protected]>
2+
// Distributed under terms of the MIT license.
3+
14
mod reader;
25
mod validator;
36

4-
pub use validator::EcmaRegexValidator;
7+
pub use validator::{EcmaRegexValidator, EcmaVersion};
58

69
#[cfg(test)]
710
mod tests {
11+
use super::*;
12+
13+
#[test]
14+
fn validate_flags_test() {
15+
let validator = EcmaRegexValidator::new(EcmaVersion::ES2018);
16+
assert_eq!(validator.validate_flags("gimuys"), Ok(()));
17+
assert_eq!(validator.validate_flags("gimgu"), Err("Duplicated flag g".to_string()));
18+
assert_eq!(validator.validate_flags("gimuf"), Err("Invalid flag f".to_string()));
19+
}
20+
821
#[test]
9-
fn it_works() {
10-
assert_eq!(2 + 2, 4);
22+
fn validate_pattern_test() {
23+
let mut validator = EcmaRegexValidator::new(EcmaVersion::ES2018);
24+
assert_eq!(validator.validate_pattern("[abc]de|fg", false), Ok(()));
25+
26+
assert_ne!(validator.validate_pattern("^[z-a]$", false), Ok(()));
27+
assert_ne!(validator.validate_pattern("0{2,1}", false), Ok(()));
28+
assert_ne!(validator.validate_pattern("\\", false), Ok(()));
1129
}
1230
}

src/reader.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ impl Reader {
3333
self.index
3434
}
3535

36-
pub fn code_point_with_offset(&self, offset: usize) -> Option<&char> {
37-
self.cps.get(offset)
36+
pub fn code_point_with_offset(&self, offset: usize) -> Option<char> {
37+
self.cps.get(offset).cloned()
3838
}
3939

4040
pub fn reset(&mut self, source: &str, start: usize, end: usize, u_flag: bool) {
@@ -70,8 +70,6 @@ impl Reader {
7070
self.cps.push_back(c);
7171
}
7272
}
73-
println!("{:?}", self.cps);
74-
println!("{:?}", self.widths);
7573
}
7674

7775
pub fn eat(&mut self, cp: char) -> bool {

0 commit comments

Comments
 (0)