Skip to content

Commit e32fb17

Browse files
committed
Fix auto strlen and add tests
1 parent 1375727 commit e32fb17

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/pinyin_compare.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int pinyin_compare(void* data, int l1, const void* s1, int l2, const void* s2) {
4444
u8_state_init(&state2);
4545

4646
int _l1 = l1 < 0 ? strlen(s1) : l1;
47-
int _l2 = l1 < 0 ? strlen(s2) : l2;
47+
int _l2 = l2 < 0 ? strlen(s2) : l2;
4848

4949
int hf1 = homonym_frequency(s1, &state1);
5050
int hf2 = homonym_frequency(s2, &state2);

tests/test_misc.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,11 @@ TEST(TestMisc, TestUmlaut) {
5757
ASSERT_LT(_pinyin_compare("", "luguan"), 0);
5858
ASSERT_LT(_pinyin_compare("", "nuǎn"), 0);
5959
}
60+
61+
TEST(TestMisc, TestAutoStrLen) {
62+
ASSERT_LT(pinyin_compare(NULL, 4, "abcde", 5, "abcde"), 0);
63+
ASSERT_GT(pinyin_compare(NULL, 5, "abcde", 4, "abcde"), 0);
64+
ASSERT_EQ(pinyin_compare(NULL, 5, "abcde", -1, "abcde"), 0);
65+
ASSERT_EQ(pinyin_compare(NULL, -1, "abcde", 5, "abcde"), 0);
66+
ASSERT_EQ(pinyin_compare(NULL, -1, "abcde", -1, "abcde"), 0);
67+
}

0 commit comments

Comments
 (0)