521
521
SVN_TEST_ASSERT(length == 1);
522
522
SVN_TEST_STRING_ASSERT(buffer, "0");
524
length = svn__i64toa(buffer, 0x8000000000000000ll);
524
length = svn__i64toa(buffer, APR_INT64_MIN);
525
525
SVN_TEST_ASSERT(length == 20);
526
526
SVN_TEST_STRING_ASSERT(buffer, "-9223372036854775808");
528
length = svn__i64toa(buffer, 0x7fffffffffffffffll);
528
length = svn__i64toa(buffer, APR_INT64_MAX);
529
529
SVN_TEST_ASSERT(length == 19);
530
530
SVN_TEST_STRING_ASSERT(buffer, "9223372036854775807");
532
length = svn__ui64toa(buffer, 0ull);
532
length = svn__ui64toa(buffer, 0u);
533
533
SVN_TEST_ASSERT(length == 1);
534
534
SVN_TEST_STRING_ASSERT(buffer, "0");
536
length = svn__ui64toa(buffer, 0xffffffffffffffffull);
536
length = svn__ui64toa(buffer, APR_UINT64_MAX);
537
537
SVN_TEST_ASSERT(length == 20);
538
538
SVN_TEST_STRING_ASSERT(buffer, "18446744073709551615");
540
return test_stringbuf_unequal("abc", "abb", pool);
544
sub_test_base36(apr_uint64_t value, const char *base36)
546
char buffer[SVN_INT64_BUFFER_SIZE];
548
apr_size_t expected_length = strlen(base36);
549
const char *end = buffer;
552
length = svn__ui64tobase36(buffer, value);
553
SVN_TEST_ASSERT(length == expected_length);
554
SVN_TEST_STRING_ASSERT(buffer, base36);
556
result = svn__base36toui64(&end, buffer);
557
SVN_TEST_ASSERT(end - buffer == length);
558
SVN_TEST_ASSERT(result == value);
560
result = svn__base36toui64(NULL, buffer);
561
SVN_TEST_ASSERT(result == value);
567
test_base36(apr_pool_t *pool)
569
SVN_ERR(sub_test_base36(0, "0"));
570
SVN_ERR(sub_test_base36(APR_UINT64_C(1234567890), "kf12oi"));
571
SVN_ERR(sub_test_base36(APR_UINT64_C(0x7fffffffffffffff), "1y2p0ij32e8e7"));
572
SVN_ERR(sub_test_base36(APR_UINT64_C(0x8000000000000000), "1y2p0ij32e8e8"));
573
SVN_ERR(sub_test_base36(APR_UINT64_MAX, "3w5e11264sgsf"));
543
578
static svn_error_t *
708
744
for (t = tests; t->stra; ++t)
711
const unsigned int score =
747
const apr_size_t score =
712
748
svn_cstring__similarity(t->stra, t->strb, &buffer, &lcs);
715
"lcs %s ~ %s score %.3f (%"APR_SIZE_T_FMT
716
") expected %.3f (%"APR_SIZE_T_FMT"))\n",
717
t->stra, t->strb, score/1000.0, lcs, t->score/1000.0, t->lcs);
751
"lcs %s ~ %s score %.6f (%"APR_SIZE_T_FMT
752
") expected %.6f (%"APR_SIZE_T_FMT"))\n",
753
t->stra, t->strb, score/1.0/SVN_STRING__SIM_RANGE_MAX,
754
lcs, t->score/1.0/SVN_STRING__SIM_RANGE_MAX, t->lcs);
719
756
if (score != t->score)
720
return fail(pool, "%s ~ %s score %.3f <> expected %.3f",
721
t->stra, t->strb, score/1000.0, t->score/1000.0);
757
return fail(pool, "%s ~ %s score %.6f <> expected %.6f",
759
score/1.0/SVN_STRING__SIM_RANGE_MAX,
760
t->score/1.0/SVN_STRING__SIM_RANGE_MAX);
723
762
if (lcs != t->lcs)
724
763
return fail(pool,
739
779
return SVN_NO_ERROR;
783
test_string_matching(apr_pool_t *pool)
785
const struct test_data_t
789
apr_size_t match_len;
790
apr_size_t rmatch_len;
799
{"", "1234567890abcdef", 0, 0},
800
{"1234567890abcdef", "", 0, 0},
801
{"1234567890abcdef", "1234567890abcdef", 16, 16},
803
/* left-side matches */
808
{"1234567890abcdef", "1234567890abcdeg", 15, 0},
809
{"1234567890abcdef_", "1234567890abcdefg", 16, 0},
810
{"12345678_0abcdef", "1234567890abcdeg", 8, 0},
811
{"1234567890abcdef", "12345678", 8, 0},
812
{"12345678", "1234567890abcdef", 8, 0},
813
{"12345678_0ab", "1234567890abcdef", 8, 0},
815
/* right-side matches */
819
{"_234567890abcdef", "1234567890abcdef", 0, 15},
820
{"_1234567890abcdef", "x1234567890abcdef", 0, 16},
821
{"1234567_90abcdef", "_1234567890abcdef", 0, 8},
822
{"1234567890abcdef", "90abcdef", 0, 8},
823
{"90abcdef", "1234567890abcdef", 0, 8},
824
{"8_0abcdef", "7890abcdef", 0, 7},
826
/* two-side matches */
827
{"bxa", "bya", 1, 1},
830
{"1234567_90abcdef", "1234567890abcdef", 7, 8},
831
{"12345678_90abcdef", "1234567890abcdef", 8, 8},
832
{"12345678_0abcdef", "1234567890abcdef", 8, 7},
833
{"123456_abcdef", "1234sdffdssdf567890abcdef", 4, 6},
834
{"1234567890abcdef", "12345678ef", 8, 2},
835
{"x_234567890abcdef", "x1234567890abcdef", 1, 15},
836
{"1234567890abcdefx", "1234567890abcdex", 15, 1},
838
/* list terminator */
842
const struct test_data_t *test;
843
for (test = tests; test->a != NULL; ++test)
845
apr_size_t a_len = strlen(test->a);
846
apr_size_t b_len = strlen(test->b);
847
apr_size_t max_match = MIN(a_len, b_len);
849
= svn_cstring__match_length(test->a, test->b, max_match);
850
apr_size_t rmatch_len
851
= svn_cstring__reverse_match_length(test->a + a_len, test->b + b_len,
854
SVN_TEST_ASSERT(match_len == test->match_len);
855
SVN_TEST_ASSERT(rmatch_len == test->rmatch_len);
862
test_string_skip_prefix(apr_pool_t *pool)
864
SVN_TEST_STRING_ASSERT(svn_cstring_skip_prefix("12345", "12345"),
866
SVN_TEST_STRING_ASSERT(svn_cstring_skip_prefix("12345", "123"),
868
SVN_TEST_STRING_ASSERT(svn_cstring_skip_prefix("12345", ""),
870
SVN_TEST_STRING_ASSERT(svn_cstring_skip_prefix("12345", "23"),
872
SVN_TEST_STRING_ASSERT(svn_cstring_skip_prefix("1", "12"),
874
SVN_TEST_STRING_ASSERT(svn_cstring_skip_prefix("", ""),
876
SVN_TEST_STRING_ASSERT(svn_cstring_skip_prefix("", "12"),
743
883
====================================================================
744
884
If you add a new test to this file, update this array.