feat: split utf string for testing

上级 92375667
pub mod scie_scanner;
pub mod scie_onig;
pub mod scie_error;
\ No newline at end of file
......@@ -3,7 +3,7 @@
use std::ptr::null_mut;
use onig::{Syntax, EncodedChars};
use std::sync::Mutex;
use crate::scanner::scie_error::ScieOnigError;
use crate::scanner::old::scie_error::ScieOnigError;
lazy_static! {
static ref REGEX_NEW_MUTEX: Mutex<()> = Mutex::new(());
......@@ -21,9 +21,6 @@ pub struct ScieOnig {
}
impl ScieOnig {
pub fn new(pattern: &str) -> Result<Self, ScieOnigError> {
}
pub fn demo_new(pattern: &str) -> Result<Self, ScieOnigError> {
let option = ScieOnigOptions::REGEX_OPTION_NONE;
let syntax = Syntax::default();
......@@ -69,7 +66,7 @@ impl ScieOnig {
#[cfg(test)]
mod tests {
use crate::scanner::scie_onig::ScieOnig;
use crate::scanner::old::scie_onig::ScieOnig;
#[test]
fn it_works() {
......
......@@ -137,7 +137,7 @@ pub fn str_vec_to_string<I, T>(iter: I) -> Vec<String>
#[cfg(test)]
mod tests {
use crate::scanner::scie_scanner::{str_vec_to_string, ScieScanner};
use crate::scanner::old::scie_scanner::{ScieScanner, str_vec_to_string};
#[test]
fn should_handle_simple_regex() {
......
......@@ -7,9 +7,9 @@ pub struct OnigScanner {
impl OnigScanner {
pub fn new(pattens: Vec<&str>) -> Self {
let str_ptrs_arr: Vec<Pointer> = vec![];
let str_len_arr: Vec<i32> = vec![];
for x in pattens {
let _str_ptrs_arr: Vec<Pointer> = vec![];
let _str_len_arr: Vec<i32> = vec![];
for _x in pattens {
}
OnigScanner { _ptr: 0 }
......
use unicode_segmentation::UnicodeSegmentation;
pub struct OnigString {
pub utf16length: i32,
pub utf8length: i32,
......@@ -10,12 +12,15 @@ pub struct OnigString {
impl OnigString {
pub fn new(str: String) -> Self {
let utf16Length = str.len();
let utf16length = str.len();
let utf8_str = str.graphemes(true).collect::<Vec<&str>>().clone();
println!("{:?}", utf8_str);
let utf8length = utf8_str.len();
OnigString {
utf16length: 0,
utf8length: 0,
utf16length: utf16length as i32,
utf8length: utf8length as i32,
utf16value: "".to_string(),
utf8value: vec![],
utf16offset_to_utf8: None,
......@@ -27,12 +32,12 @@ impl OnigString {
#[cfg(test)]
mod tests {
use crate::scanner::onig_scanner::OnigScanner;
use crate::scanner::onig_string::OnigString;
#[test]
fn it_show_works_works() {
OnigString::new(String::from(""));
assert!(true)
let onig_string = OnigString::new(String::from("a💻bYX"));
assert_eq!(8, onig_string.utf16length);
assert_eq!(5, onig_string.utf8length);
}
}
......@@ -4,6 +4,11 @@ import UtfString from './utf-string';
test('constructor', (t) => {
const utfString = new UtfString("hello, world");
t.log(utfString);
t.is(utfString.utf8Length, 12);
});
test('utf8 length', (t) => {
const utfString = new UtfString("a💻bYX");
console.log(utfString);
t.is(utfString.utf8Length, 8);
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册