File: JsonParser.cpp

package info (click to toggle)
waybar 0.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,364 kB
  • sloc: cpp: 24,698; xml: 742; python: 146; ansic: 77; makefile: 26
file content (45 lines) | stat: -rw-r--r-- 1,472 bytes parent folder | download | duplicates (2)
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
#include "util/json.hpp"

#if __has_include(<catch2/catch_test_macros.hpp>)
#include <catch2/catch_test_macros.hpp>
#else
#include <catch2/catch.hpp>
#endif

TEST_CASE("Simple json", "[json]") {
  SECTION("Parse simple json") {
    std::string stringToTest = R"({"number": 5, "string": "test"})";
    waybar::util::JsonParser parser;
    Json::Value jsonValue = parser.parse(stringToTest);
    REQUIRE(jsonValue["number"].asInt() == 5);
    REQUIRE(jsonValue["string"].asString() == "test");
  }
}

TEST_CASE("Json with unicode", "[json]") {
  SECTION("Parse json with unicode") {
    std::string stringToTest = R"({"test": "\xab"})";
    waybar::util::JsonParser parser;
    Json::Value jsonValue = parser.parse(stringToTest);
    // compare with "\u00ab" because "\xab" is replaced with "\u00ab" in the parser
    REQUIRE(jsonValue["test"].asString() == "\u00ab");
  }
}

TEST_CASE("Json with emoji", "[json]") {
  SECTION("Parse json with emoji") {
    std::string stringToTest = R"({"test": "😊"})";
    waybar::util::JsonParser parser;
    Json::Value jsonValue = parser.parse(stringToTest);
    REQUIRE(jsonValue["test"].asString() == "😊");
  }
}

TEST_CASE("Json with chinese characters", "[json]") {
  SECTION("Parse json with chinese characters") {
    std::string stringToTest = R"({"test": "你好"})";
    waybar::util::JsonParser parser;
    Json::Value jsonValue = parser.parse(stringToTest);
    REQUIRE(jsonValue["test"].asString() == "你好");
  }
}