<commit_before>#include "gtest/gtest.h"
#include <ten/json.hh>
#include <array>

#include "ten/logging.hh"
#include "ten/jsonstream.hh"
#include <map>

using namespace std;
using namespace ten;

const char json_text[] =
"{ \"store\": {"
"    \"book\": ["
"      { \"category\": \"reference\","
"        \"author\": \"<NAME>\","
"        \"title\": \"Sayings of the Century\","
"        \"price\": 8.95"
"      },"
"      { \"category\": \"fiction\","
"        \"author\": \"<NAME>\","
"        \"title\": \"Sword of Honour\","
"        \"price\": 12.99"
"      },"
"      { \"category\": \"fiction\","
"        \"author\": \"<NAME>\","
"        \"title\": \"Moby Dick\","
"        \"isbn\": \"0-553-21311-3\","
"        \"price\": 8.99"
"      },"
"      { \"category\": \"fiction\","
"        \"author\": \"<NAME>\","
"        \"title\": \"The Lord of the Rings\","
"        \"isbn\": \"0-395-19395-8\","
"        \"price\": 22.99"
"      }"
"    ],"
"    \"bicycle\": {"
"      \"color\": \"red\","
"      \"price\": 19.95"
"    }"
"  }"
"}";


TEST(Json, Path1) {
    json o{json::load(json_text)};
    ASSERT_TRUE(o.get());

    static const char a1[] = "[\"<NAME>\", \"<NAME>\", \"<NAME>\", \"<NAME>\"]";
    json r1{o.path("/store/book/author")};
    EXPECT_EQ(json::load(a1), r1);

    json r2{o.path("//author")};
    EXPECT_EQ(json::load(a1), r2);

    // jansson hashtable uses size_t for hash
    // we think this is causing the buckets to change on 32bit vs. 64bit
#if (__SIZEOF_SIZE_T__ == 4)
    static const char a3[] = "[{\"category\": \"reference\", \"author\": \"<NAME>\", \"title\": \"Sayings of the Century\", \"price\": 8.95}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"Sword of Honour\", \"price\": 12.99}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"Moby Dick\", \"isbn\": \"0-553-21311-3\", \"price\": 8.99}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99}, {\"color\": \"red\", \"price\": 19.95}]";
#elif (__SIZEOF_SIZE_T__ == 8)
    static const char a3[] = "[{\"color\": \"red\", \"price\": 19.95}, {\"category\": \"reference\", \"author\": \"<NAME>\", \"title\": \"Sayings of the Century\", \"price\": 8.95}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"Sword of Honour\", \"price\": 12.99}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"Moby Dick\", \"isbn\": \"0-553-21311-3\", \"price\": 8.99}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99}]";
#endif
    json r3{o.path("/store/*")};
    json t3{json::load(a3)};
    EXPECT_EQ(t3, r3);

#if (__SIZEOF_SIZE_T__ == 4)
    static const char a4[] = "[8.95, 12.99, 8.99, 22.99, 19.95]";
#elif (__SIZEOF_SIZE_T__ == 8)
    static const char a4[] = "[19.95, 8.95, 12.99, 8.99, 22.99]";
#endif
    json r4{o.path("/store//price")};
    EXPECT_EQ(json::load(a4), r4);

    static const char a5[] = "{\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99}";
    json r5{o.path("//book[3]")};
    EXPECT_EQ(json::load(a5), r5);

    static const char a6[] = "\"<NAME>\"";
    json r6{o.path("/store/book[3]/author")};
    EXPECT_EQ(json::load(a6), r6);
    EXPECT_TRUE(json::load(a6) == r6);

    static const char a7[] = "[{\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"Sword of Honour\", \"price\": 12.99}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"Moby Dick\", \"isbn\": \"0-553-21311-3\", \"price\": 8.99}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99}]";
    json r7{o.path("/store/book[category=\"fiction\"]")};
    EXPECT_EQ(json::load(a7), r7);
}

TEST(Json, Path2) {
    json o{json::load("[{\"type\": 0}, {\"type\": 1}]")};<commit_msg>remove test when using old jansson<commit_after>#include "gtest/gtest.h"
#include <ten/json.hh>
#include <array>

#include "ten/logging.hh"
#include "ten/jsonstream.hh"
#include <map>

using namespace std;
using namespace ten;

const char json_text[] =
"{ \"store\": {"
"    \"book\": ["
"      { \"category\": \"reference\","
"        \"author\": \"<NAME>\","
"        \"title\": \"Sayings of the Century\","
"        \"price\": 8.95"
"      },"
"      { \"category\": \"fiction\","
"        \"author\": \"<NAME>\","
"        \"title\": \"Sword of Honour\","
"        \"price\": 12.99"
"      },"
"      { \"category\": \"fiction\","
"        \"author\": \"<NAME>\","
"        \"title\": \"Moby Dick\","
"        \"isbn\": \"0-553-21311-3\","
"        \"price\": 8.99"
"      },"
"      { \"category\": \"fiction\","
"        \"author\": \"<NAME>\","
"        \"title\": \"The Lord of the Rings\","
"        \"isbn\": \"0-395-19395-8\","
"        \"price\": 22.99"
"      }"
"    ],"
"    \"bicycle\": {"
"      \"color\": \"red\","
"      \"price\": 19.95"
"    }"
"  }"
"}";


TEST(Json, Path1) {
    json o{json::load(json_text)};
    ASSERT_TRUE(o.get());

    static const char a1[] = "[\"<NAME>\", \"<NAME>\", \"<NAME>\", \"<NAME>\"]";
    json r1{o.path("/store/book/author")};
    EXPECT_EQ(json::load(a1), r1);

    json r2{o.path("//author")};
    EXPECT_EQ(json::load(a1), r2);

    // jansson hashtable uses size_t for hash
    // we think this is causing the buckets to change on 32bit vs. 64bit
#if (__SIZEOF_SIZE_T__ == 4)
    static const char a3[] = "[{\"category\": \"reference\", \"author\": \"<NAME>\", \"title\": \"Sayings of the Century\", \"price\": 8.95}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"Sword of Honour\", \"price\": 12.99}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"Moby Dick\", \"isbn\": \"0-553-21311-3\", \"price\": 8.99}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99}, {\"color\": \"red\", \"price\": 19.95}]";
#elif (__SIZEOF_SIZE_T__ == 8)
    static const char a3[] = "[{\"color\": \"red\", \"price\": 19.95}, {\"category\": \"reference\", \"author\": \"<NAME>\", \"title\": \"Sayings of the Century\", \"price\": 8.95}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"Sword of Honour\", \"price\": 12.99}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"Moby Dick\", \"isbn\": \"0-553-21311-3\", \"price\": 8.99}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99}]";
#endif
    json r3{o.path("/store/*")};
    json t3{json::load(a3)};
    EXPECT_EQ(t3, r3);

#if (__SIZEOF_SIZE_T__ == 4)
    static const char a4[] = "[8.95, 12.99, 8.99, 22.99, 19.95]";
#elif (__SIZEOF_SIZE_T__ == 8)
    static const char a4[] = "[19.95, 8.95, 12.99, 8.99, 22.99]";
#endif
    json r4{o.path("/store//price")};
    EXPECT_EQ(json::load(a4), r4);

    static const char a5[] = "{\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99}";
    json r5{o.path("//book[3]")};
    EXPECT_EQ(json::load(a5), r5);

#if JANSSON_VERSION_HEX >= 0x020300
    static const char a6[] = "\"<NAME>\"";
    json r6{o.path("/store/book[3]/author")};
    EXPECT_EQ(json::load(a6), r6);
    EXPECT_TRUE(json::load(a6) == r6);
#endif

    static const char a7[] = "[{\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"Sword of Honour\", \"price\": 12.99}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"Moby Dick\", \"isbn\": \"0-553-21311-3\", \"price\": 8.99}, {\"category\": \"fiction\", \"author\": \"<NAME>\", \"title\": \"The Lord of the Rings\", \"isbn\": \"0-395-19395-8\", \"price\": 22.99}]";
    json r7{o.path("/store/book[category=\"fiction\"]")};
    EXPECT_EQ(json::load(a7), r7);
}

TEST(Json, Path2) {
    json o{json::load("[{\"type\": 0}, {\"type\": 1}]")};
{'fraction_non_alphanumeric': 0.3192441571357534, 'fraction_numerical': 0.061039283938339135, 'mean_word_length': 2.658481127785357, 'pattern_counts': {'":': 168, '<': 51, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '189095', 'n_tokens_mistral': 3273, 'n_tokens_neox': 2960, 'n_words': 702}