1#!perl
2
3use Test::More tests => 9;
4use XS::APItest;
5
6my $abc = "abc";
7ok  sv_streq($abc, "abc"), '$abc eq "abc"';
8ok !sv_streq($abc, "def"), '$abc ne "def"';
9
10{
11    # U+00B6 = PARAGRAPH SEPARATOR
12    #  UTF-8 on ASCII boxes: \xc2 \xb6
13    my $psep_LATIN1 = "psep\xb6";
14    utf8::upgrade(my $psep_UNICODE = "psep\x{00b6}");
15    utf8::encode (my $psep_UTF8    = "psep\x{00b6}");
16
17    # Latin-1 and Unicode strings should compare equal despite containing
18    # different underlying bytes in the SvPV
19    ok sv_streq($psep_LATIN1, $psep_UNICODE), 'sv_streq handles UTF8 strings';
20
21    # UTF-8 and Unicode strings should not compare equal, even though they
22    # contain the same bytes in the SvPV
23    ok !sv_streq($psep_UTF8, $psep_UNICODE), 'sv_streq takes UTF8ness into account';
24}
25
26# GMAGIC
27"ABC" =~ m/(\w+)/;
28ok !sv_streq_flags($1, "ABC", 0), 'sv_streq_flags with no flags does not GETMAGIC';
29ok  sv_streq_flags($1, "ABC", SV_GMAGIC), 'sv_streq_flags with SV_GMAGIC does';
30
31# overloading
32{
33    package AlwaysABC {
34        use overload
35            'eq' => sub { return $_[1] eq "ABC" },
36            '""' => sub { "not-a-string" };
37    }
38    my $obj = bless([], "AlwaysABC");
39
40    ok  sv_streq($obj, "ABC"), 'AlwaysABC is "ABC"';
41    ok !sv_streq($obj, "DEF"), 'AlwaysABC is not "DEF"';
42
43    ok !sv_streq_flags($obj, "ABC", SV_SKIP_OVERLOAD), 'AlwaysABC is not "ABC" with SV_SKIP_OVERLOAD';
44}
45