File: string_piece.cc

package info (click to toggle)
pageedit 2.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,956 kB
  • sloc: ansic: 31,806; cpp: 15,036; python: 1,141; javascript: 87; sh: 13; makefile: 7
file content (84 lines) | stat: -rw-r--r-- 2,450 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: jdtang@google.com (Jonathan Tang)

#include "string_piece.h"

#include <stdlib.h>
#include <string.h>

#include "gtest/gtest.h"
#include "parser.h"
#include "test_utils.h"
#include "util.h"

namespace {

typedef GumboTest GumboStringPieceTest;

#define INIT_GUMBO_STRING(varname, literal) \
    GumboStringPiece varname = { literal, sizeof(literal) - 1 }

TEST_F(GumboStringPieceTest, Equal) {
  INIT_GUMBO_STRING(str1, "foo");
  INIT_GUMBO_STRING(str2, "foo");
  EXPECT_TRUE(gumbo_string_equals(&str1, &str2));
}

TEST_F(GumboStringPieceTest, NotEqual_DifferingCase) {
  INIT_GUMBO_STRING(str1, "foo");
  INIT_GUMBO_STRING(str2, "Foo");
  EXPECT_FALSE(gumbo_string_equals(&str1, &str2));
}

TEST_F(GumboStringPieceTest, NotEqual_Str1Shorter) {
  INIT_GUMBO_STRING(str1, "foo");
  INIT_GUMBO_STRING(str2, "foobar");
  EXPECT_FALSE(gumbo_string_equals(&str1, &str2));
}

TEST_F(GumboStringPieceTest, NotEqual_Str2Shorter) {
  INIT_GUMBO_STRING(str1, "foobar");
  INIT_GUMBO_STRING(str2, "foo");
  EXPECT_FALSE(gumbo_string_equals(&str1, &str2));
}

TEST_F(GumboStringPieceTest, NotEqual_DifferentText) {
  INIT_GUMBO_STRING(str1, "bar");
  INIT_GUMBO_STRING(str2, "foo");
  EXPECT_FALSE(gumbo_string_equals(&str1, &str2));
}

TEST_F(GumboStringPieceTest, CaseEqual) {
  INIT_GUMBO_STRING(str1, "foo");
  INIT_GUMBO_STRING(str2, "fOO");
  EXPECT_TRUE(gumbo_string_equals_ignore_case(&str1, &str2));
}

TEST_F(GumboStringPieceTest, CaseNotEqual_Str2Shorter) {
  INIT_GUMBO_STRING(str1, "foobar");
  INIT_GUMBO_STRING(str2, "foo");
  EXPECT_FALSE(gumbo_string_equals_ignore_case(&str1, &str2));
}

TEST_F(GumboStringPieceTest, Copy) {
  INIT_GUMBO_STRING(str1, "bar");
  GumboStringPiece str2;
  gumbo_string_copy(&str2, &str1);
  EXPECT_TRUE(gumbo_string_equals(&str1, &str2));
  gumbo_free((void*) str2.data);
}

}  // namespace