MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/stl/string_interner.cpp:12–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include "fl/stl/string_view.h" // for string_view
11
12FL_TEST_FILE(FL_FILEPATH) {
13
14FL_TEST_CASE("StringInterner - basic interning") {
15 fl::StringInterner interner;
16 // Use string > 64 bytes (SSO threshold) to trigger actual interning
17 fl::string s1 = interner.intern("this_is_a_long_string_that_exceeds_the_sso_threshold_of_64_bytes_to_test_interning");
18 FL_CHECK(s1.size() == 82); // Actual length
19 FL_CHECK(interner.size() == 1);
20}
21
22FL_TEST_CASE("StringInterner - deduplication") {
23 fl::StringInterner interner;
24 // Use string > 64 bytes to trigger actual interning
25 const char* long_str = "this_is_a_long_string_that_exceeds_the_sso_threshold_of_64_bytes_for_dedup_test";
26 fl::string s1 = interner.intern(long_str);
27 fl::string s2 = interner.intern(long_str);
28 FL_CHECK(s1 == s2);
29 const char* p1 = s1.c_str();
30 const char* p2 = s2.c_str();
31 FL_CHECK(p1 == p2); // Should point to same StringHolder data
32 FL_CHECK(interner.size() == 1);
33}
34
35FL_TEST_CASE("StringInterner - contains") {
36 fl::StringInterner interner;
37 const char* long_str = "this_is_a_long_string_that_exceeds_the_sso_threshold_of_64_bytes_for_contains_test";
38 FL_CHECK_FALSE(interner.contains(long_str));
39 interner.intern(long_str);
40 FL_CHECK(interner.contains(long_str));
41}
42
43// NOTE: get() by index removed - hash map doesn't support index-based access
44// Use contains() to check if a string is interned instead
45
46FL_TEST_CASE("StringInterner - API overloads") {
47 fl::StringInterner interner;
48
49 // All test strings must be > 64 bytes to trigger interning
50 const char* str1 = "this_is_a_very_long_string_view_that_exceeds_64_bytes_sso_threshold_test1";
51 const char* str2 = "this_is_a_very_long_cstring_that_exceeds_64_bytes_sso_threshold_test2xxxx";
52 const char* str3 = "this_is_a_very_long_fl_string_that_exceeds_64_bytes_sso_threshold_test3xx";
53 const char* str4 = "this_is_a_very_long_span_string_that_exceeds_64_bytes_sso_threshold_test4";
54
55 // Test intern(string_view)
56 fl::string_view sv(str1);
57 fl::string s1 = interner.intern(sv);
58 FL_CHECK(s1 == str1);
59 FL_CHECK(interner.size() == 1);
60
61 // Test intern(const char*)
62 fl::string s2 = interner.intern(str2);
63 FL_CHECK(s2 == str2);
64 FL_CHECK(interner.size() == 2);
65
66 // Test intern(fl::string)
67 fl::string str(str3);
68 fl::string s3 = interner.intern(str);
69 FL_CHECK(s3 == str3);

Callers

nothing calls this directly

Calls 9

strlenFunction · 0.85
snprintfFunction · 0.85
memcmpFunction · 0.85
internMethod · 0.80
sizeMethod · 0.45
c_strMethod · 0.45
containsMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected