From a1fceca87c7a1972a965bc16125d97b0349bc0c7 Mon Sep 17 00:00:00 2001 From: ljy9810 Date: Thu, 12 Jun 2025 19:40:43 +0800 Subject: [PATCH] =?UTF-8?q?ylong=5Fjosn=20test=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ljy9810 --- BUILD.gn | 35 ++++++++++++++++++++++++++++++++--- bundle.json | 11 +++++++++-- src/deserializer.rs | 4 ++-- src/states.rs | 8 ++++---- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index b693e87..83a6c8c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -23,10 +23,18 @@ ohos_rust_shared_library("lib") { part_name = "ylong_json" sources = [ "src/lib.rs" ] + deps = [ - "//third_party/rust/crates/libc:lib", "//third_party/rust/crates/serde/serde:lib", ] + + if (defined(global_parts_info) && + !defined(global_parts_info.third_party_rust_libc)) { + deps += [ "//third_party/rust/crates/libc:lib" ] + } else { + external_deps += [ "rust_libc:lib" ] + } + features = [ "default", "vec_array", @@ -36,14 +44,27 @@ ohos_rust_shared_library("lib") { } ohos_rust_unittest("rust_ylong_json_unit_test") { - module_out_path = "commonlibrary/rust/ylong_json" + module_out_path = "ylong_json/ylong_json" sources = [ "src/lib.rs" ] deps = [ ":lib", - "//third_party/rust/crates/libc:lib", "//third_party/rust/crates/serde/serde:lib", ] + if (defined(global_parts_info) && + !defined(global_parts_info.third_party_rust_libc)) { + deps += [ "//third_party/rust/crates/libc:lib" ] + } else { + external_deps += [ "rust_libc:lib" ] + } + + if (defined(global_parts_info) && + !defined(global_parts_info.third_party_rust_serde)) { + deps += [ "//third_party/rust/crates/serde/serde:lib" ] + } else { + external_deps += [ "rust_serde:lib" ] + } + rustflags = [ "--cfg=feature=\"default\"", "--cfg=feature=\"vec_array\"", @@ -51,3 +72,11 @@ ohos_rust_unittest("rust_ylong_json_unit_test") { "--cfg=feature=\"ascii_only\"", ] } + +group("unittest") { + testonly = true + deps = [] + if (!use_clang_coverage) { + deps += [ ":rust_ylong_json_unit_test" ] + } +} \ No newline at end of file diff --git a/bundle.json b/bundle.json index 57b72e3..fa5efde 100644 --- a/bundle.json +++ b/bundle.json @@ -25,7 +25,12 @@ ], "rom": "200KB", "ram": "~200KB", - "deps": {}, + "deps": { + "components": [ + "rust_libc" + ], + "third_party": [] + }, "build": { "sub_component": [], "inner_kits": [ @@ -37,7 +42,9 @@ "name": "//commonlibrary/rust/ylong_json:lib" } ], - "test": [] + "test": [ + "//commonlibrary/rust/ylong_json:unittest" + ] } } } \ No newline at end of file diff --git a/src/deserializer.rs b/src/deserializer.rs index 27b54d4..b6bdea7 100644 --- a/src/deserializer.rs +++ b/src/deserializer.rs @@ -922,10 +922,10 @@ mod ut_test_for_deserializer { let slice_map = r#"{ "apple" : 3 }"#.as_bytes(); let mut expected = HashMap::new(); - expected.insert("appple", 3); + expected.insert(String::from("apple"), 3); assert_eq!( expected, - crate::from_slice::>(slice_map).unwrap() + crate::from_slice::>(slice_map).unwrap() ); } diff --git a/src/states.rs b/src/states.rs index 8aa0ffb..0aa80c8 100644 --- a/src/states.rs +++ b/src/states.rs @@ -800,20 +800,20 @@ mod ut_states { assert!(parse_string(&mut deserializer).is_err()); // 3.A backslash is followed by a terminator. - let str = r#"\"#; + let str = r"\"; let mut deserializer = Deserializer::new_from_slice(str.as_bytes()); assert!(parse_string(&mut deserializer).is_err()); // 4.Illegal unicode characters. - let str = r#"\uBEEF"#; + let str = r"\uBEEF"; let mut deserializer = Deserializer::new_from_slice(str.as_bytes()); assert!(parse_string(&mut deserializer).is_err()); - let str = r#"\uZ000"#; + let str = r"\uZ000"; let mut deserializer = Deserializer::new_from_slice(str.as_bytes()); assert!(parse_string(&mut deserializer).is_err()); - let str = r#"\u"#; + let str = r"\u"; let mut deserializer = Deserializer::new_from_slice(str.as_bytes()); assert!(parse_string(&mut deserializer).is_err()); -- Gitee