Skip to content

Commit

Permalink
Add tests for unicode dot in both str and bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
RustyYato committed Feb 16, 2024
1 parent d44d81b commit 0aa58a0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ extern crate core as std;
pub use logos_derive::Logos;
use std::fmt::Debug;

#[cfg(test)]
mod tests;

mod lexer;
pub mod source;

Expand Down
57 changes: 57 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use crate::Logos;

#[derive(Logos, Debug, PartialEq)]
#[logos(crate = crate)]
enum TestUnicodeDot {
#[regex(".")]
Dot,
}

#[test]
fn test_unicode_dot_str_ascii() {
let mut lexer = TestUnicodeDot::lexer("a");
assert_eq!(lexer.next(), Some(Ok(TestUnicodeDot::Dot)));
assert_eq!(lexer.remainder(), "");
assert_eq!(lexer.next(), None);
}

#[test]
fn test_unicode_dot_str_unicode() {
let mut lexer = TestUnicodeDot::lexer("");
assert_eq!(lexer.next(), Some(Ok(TestUnicodeDot::Dot)));
assert_eq!(lexer.remainder(), "");
assert_eq!(lexer.next(), None);
}

#[derive(Logos, Debug, PartialEq)]
#[logos(crate = crate)]
enum TestUnicodeDotBytes {
#[regex(".", priority = 100)]
Dot,
#[regex(b".", priority = 0)]
InvalidUtf8,
}

#[test]
fn test_unicode_dot_bytes_ascii() {
let mut lexer = TestUnicodeDotBytes::lexer(b"a");
assert_eq!(lexer.next(), Some(Ok(TestUnicodeDotBytes::Dot)));
assert_eq!(lexer.remainder(), b"");
assert_eq!(lexer.next(), None);
}

#[test]
fn test_unicode_dot_bytes_unicode() {
let mut lexer = TestUnicodeDotBytes::lexer("".as_bytes());
assert_eq!(lexer.next(), Some(Ok(TestUnicodeDotBytes::Dot)));
assert_eq!(lexer.remainder(), b"");
assert_eq!(lexer.next(), None);
}

#[test]
fn test_unicode_dot_bytes_invalid_utf8() {
let mut lexer = TestUnicodeDotBytes::lexer(b"\xff");
assert_eq!(lexer.next(), Some(Ok(TestUnicodeDotBytes::InvalidUtf8)));
assert_eq!(lexer.remainder(), b"");
assert_eq!(lexer.next(), None);
}

0 comments on commit 0aa58a0

Please sign in to comment.