# Global Metrics

path: .metrics.nargs.average
old: 0.0
new: 1.8888888888888888
path: .metrics.nargs.sum
old: 0.0
new: 17.0
path: .metrics.mi.mi_original
old: 95.48575085042714
new: 27.93990619479956
path: .metrics.mi.mi_sei
old: 107.12348859824856
new: -12.09581147161278
path: .metrics.mi.mi_visual_studio
old: 55.839620380366746
new: 16.339126429707346
path: .metrics.nom.functions
old: 1.0
new: 9.0
path: .metrics.nom.total
old: 1.0
new: 9.0
path: .metrics.cyclomatic.average
old: 1.5
new: 1.9090909090909092
path: .metrics.cyclomatic.sum
old: 6.0
new: 21.0
path: .metrics.halstead.level
old: 0.225
new: 0.019718792866941014
path: .metrics.halstead.N2
old: 10.0
new: 648.0
path: .metrics.halstead.n1
old: 8.0
new: 18.0
path: .metrics.halstead.N1
old: 15.0
new: 771.0
path: .metrics.halstead.purity_ratio
old: 2.1011730005192324
new: 0.6076744227516312
path: .metrics.halstead.time
old: 25.231252106483577
new: 28206.160273185087
path: .metrics.halstead.vocabulary
old: 17.0
new: 133.0
path: .metrics.halstead.effort
old: 454.1625379167044
new: 507710.8849173316
path: .metrics.halstead.length
old: 25.0
new: 1419.0
path: .metrics.halstead.difficulty
old: 4.444444444444445
new: 50.71304347826087
path: .metrics.halstead.n2
old: 9.0
new: 115.0
path: .metrics.halstead.bugs
old: 0.019694862389754937
new: 2.1214024279582273
path: .metrics.halstead.volume
old: 102.18657103125848
new: 10011.445775976188
path: .metrics.halstead.estimated_program_length
old: 52.529325012980806
new: 862.2900058845647
path: .metrics.loc.lloc
old: 3.0
new: 111.0
path: .metrics.loc.cloc
old: 11.0
new: 21.0
path: .metrics.loc.ploc
old: 10.0
new: 204.0
path: .metrics.loc.blank
old: 1.0
new: 39.0
path: .metrics.loc.sloc
old: 22.0
new: 264.0
path: .metrics.cognitive.average
old: 2.0
new: 1.0
path: .metrics.cognitive.sum
old: 2.0
new: 9.0

# Spaces Data

## Minimal test - lines (25, 45)

path: .spaces[0].spaces[0].metrics.cognitive.average
old: 2.0
new: 1.0
path: .spaces[0].spaces[0].metrics.cognitive.sum
old: 2.0
new: 1.0
path: .spaces[0].spaces[0].metrics.cyclomatic.sum
old: 4.0
new: 2.0
path: .spaces[0].spaces[0].metrics.mi.mi_original
old: 115.3965773974688
new: 87.85154400135815
path: .spaces[0].spaces[0].metrics.mi.mi_sei
old: 91.18849739249276
new: 51.24577459199416
path: .spaces[0].spaces[0].metrics.mi.mi_visual_studio
old: 67.483378595011
new: 51.3751719306188
path: .spaces[0].spaces[0].metrics.loc.blank
old: 1.0
new: 5.0
path: .spaces[0].spaces[0].metrics.loc.ploc
old: 6.0
new: 16.0
path: .spaces[0].spaces[0].metrics.loc.lloc
old: 3.0
new: 8.0
path: .spaces[0].spaces[0].metrics.loc.sloc
old: 7.0
new: 21.0
path: .spaces[0].spaces[0].metrics.nargs.average
old: 0.0
new: 2.0
path: .spaces[0].spaces[0].metrics.nargs.sum
old: 0.0
new: 2.0
path: .spaces[0].spaces[0].metrics.halstead.length
old: 22.0
new: 115.0
path: .spaces[0].spaces[0].metrics.halstead.effort
old: 392.9215684726281
new: 7737.703312245161
path: .spaces[0].spaces[0].metrics.halstead.vocabulary
old: 15.0
new: 40.0
path: .spaces[0].spaces[0].metrics.halstead.time
old: 21.828976026257116
new: 429.8724062358423
path: .spaces[0].spaces[0].metrics.halstead.purity_ratio
old: 1.984158384291056
new: 1.5445694593588415
path: .spaces[0].spaces[0].metrics.halstead.difficulty
old: 4.571428571428571
new: 12.642857142857142
path: .spaces[0].spaces[0].metrics.halstead.n2
old: 7.0
new: 28.0
path: .spaces[0].spaces[0].metrics.halstead.N2
old: 8.0
new: 59.0
path: .spaces[0].spaces[0].metrics.halstead.N1
old: 14.0
new: 56.0
path: .spaces[0].spaces[0].metrics.halstead.bugs
old: 0.017881995912937442
new: 0.13040276325967382
path: .spaces[0].spaces[0].metrics.halstead.estimated_program_length
old: 43.65148445440323
new: 177.62548782626678
path: .spaces[0].spaces[0].metrics.halstead.volume
old: 85.95159310338741
new: 612.0217309120467
path: .spaces[0].spaces[0].metrics.halstead.n1
old: 8.0
new: 12.0
path: .spaces[0].spaces[0].metrics.halstead.level
old: 0.21875
new: 0.07909604519774012

### Code

    TEST(UTF, Valid)
    {
      for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) {
        nsDependentCString str8(ValidStrings[i].m8);
        nsDependentString str16(ValidStrings[i].m16);

        EXPECT_TRUE(NS_ConvertUTF16toUTF8(str16).Equals(str8));

        EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).Equals(str16));

        nsCString tmp8("string ");
        AppendUTF16toUTF8(str16, tmp8);
        EXPECT_TRUE(tmp8.Equals("string "_ns + str8));

        nsString tmp16(u"string "_ns);
        AppendUTF8toUTF16(str8, tmp16);
        EXPECT_TRUE(tmp16.Equals(u"string "_ns + str16));

        EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0);
      }
    }

## Minimal test - lines (23, 264)

path: .spaces[0].metrics.cyclomatic.sum
old: 5.0
new: 20.0
path: .spaces[0].metrics.cyclomatic.average
old: 1.6666666666666667
new: 2.0
path: .spaces[0].metrics.cognitive.average
old: 2.0
new: 1.0
path: .spaces[0].metrics.cognitive.sum
old: 2.0
new: 9.0
path: .spaces[0].metrics.loc.ploc
old: 8.0
new: 192.0
path: .spaces[0].metrics.loc.cloc
old: 1.0
new: 15.0
path: .spaces[0].metrics.loc.sloc
old: 9.0
new: 242.0
path: .spaces[0].metrics.loc.lloc
old: 3.0
new: 111.0
path: .spaces[0].metrics.loc.blank
old: 0.0
new: 35.0
path: .spaces[0].metrics.mi.mi_sei
old: 108.94295221324106
new: -12.000871568370876
path: .spaces[0].metrics.mi.mi_visual_studio
old: 64.63178435761432
new: 17.37060999512604
path: .spaces[0].metrics.mi.mi_original
old: 110.5203512515205
new: 29.70374309166553
path: .spaces[0].metrics.nom.functions
old: 1.0
new: 9.0
path: .spaces[0].metrics.nom.total
old: 1.0
new: 9.0
path: .spaces[0].metrics.nargs.average
old: 0.0
new: 1.8888888888888888
path: .spaces[0].metrics.nargs.sum
old: 0.0
new: 17.0
path: .spaces[0].metrics.halstead.N1
old: 15.0
new: 770.0
path: .spaces[0].metrics.halstead.purity_ratio
old: 2.0
new: 0.5540159299580287
path: .spaces[0].metrics.halstead.vocabulary
old: 16.0
new: 123.0
path: .spaces[0].metrics.halstead.n1
old: 8.0
new: 18.0
path: .spaces[0].metrics.halstead.time
old: 24.0
new: 29697.564524782196
path: .spaces[0].metrics.halstead.length
old: 24.0
new: 1408.0
path: .spaces[0].metrics.halstead.level
old: 0.2222222222222222
new: 0.018286311389759665
path: .spaces[0].metrics.halstead.difficulty
old: 4.5
new: 54.68571428571428
path: .spaces[0].metrics.halstead.estimated_program_length
old: 48.0
new: 780.0544293809045
path: .spaces[0].metrics.halstead.N2
old: 9.0
new: 638.0
path: .spaces[0].metrics.halstead.bugs
old: 0.019048812623618388
new: 2.1955380685248365
path: .spaces[0].metrics.halstead.effort
old: 432.0
new: 534556.1614460795
path: .spaces[0].metrics.halstead.n2
old: 8.0
new: 105.0
path: .spaces[0].metrics.halstead.volume
old: 96.0
new: 9775.06042351765

### Code

    namespace TestUTF {

    TEST(UTF, Valid)
    {
      for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) {
        nsDependentCString str8(ValidStrings[i].m8);
        nsDependentString str16(ValidStrings[i].m16);

        EXPECT_TRUE(NS_ConvertUTF16toUTF8(str16).Equals(str8));

        EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).Equals(str16));

        nsCString tmp8("string ");
        AppendUTF16toUTF8(str16, tmp8);
        EXPECT_TRUE(tmp8.Equals("string "_ns + str8));

        nsString tmp16(u"string "_ns);
        AppendUTF8toUTF16(str8, tmp16);
        EXPECT_TRUE(tmp16.Equals(u"string "_ns + str16));

        EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0);
      }
    }

    TEST(UTF, Invalid16)
    {
      for (unsigned int i = 0; i < ArrayLength(Invalid16Strings); ++i) {
        nsDependentString str16(Invalid16Strings[i].m16);
        nsDependentCString str8(Invalid16Strings[i].m8);

        EXPECT_TRUE(NS_ConvertUTF16toUTF8(str16).Equals(str8));

        nsCString tmp8("string ");
        AppendUTF16toUTF8(str16, tmp8);
        EXPECT_TRUE(tmp8.Equals("string "_ns + str8));

        EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0);
      }
    }

    TEST(UTF, Invalid8)
    {
      for (unsigned int i = 0; i < ArrayLength(Invalid8Strings); ++i) {
        nsDependentString str16(Invalid8Strings[i].m16);
        nsDependentCString str8(Invalid8Strings[i].m8);

        EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).Equals(str16));

        nsString tmp16(u"string "_ns);
        AppendUTF8toUTF16(str8, tmp16);
        EXPECT_TRUE(tmp16.Equals(u"string "_ns + str16));

        EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0);
      }
    }

    TEST(UTF, Malformed8)
    {
      for (unsigned int i = 0; i < ArrayLength(Malformed8Strings); ++i) {
        nsDependentString str16(Malformed8Strings[i].m16);
        nsDependentCString str8(Malformed8Strings[i].m8);

        EXPECT_TRUE(NS_ConvertUTF8toUTF16(str8).Equals(str16));

        nsString tmp16(u"string "_ns);
        AppendUTF8toUTF16(str8, tmp16);
        EXPECT_TRUE(tmp16.Equals(u"string "_ns + str16));

        EXPECT_EQ(CompareUTF8toUTF16(str8, str16), 0);
      }
    }

    TEST(UTF, Hash16)
    {
      for (unsigned int i = 0; i < ArrayLength(ValidStrings); ++i) {
        nsDependentCString str8(ValidStrings[i].m8);
        bool err;
        EXPECT_EQ(HashString(ValidStrings[i].m16),
                  HashUTF8AsUTF16(str8.get(), str8.Length(), &err));
        EXPECT_FALSE(err);
      }

      for (unsigned int i = 0; i < ArrayLength(Invalid8Strings); ++i) {
        nsDependentCString str8(Invalid8Strings[i].m8);
        bool err;
        EXPECT_EQ(HashUTF8AsUTF16(str8.get(), str8.Length(), &err), 0u);
        EXPECT_TRUE(err);
      }

      for (unsigned int i = 0; i < ArrayLength(Malformed8Strings); ++i) {
        nsDependentCString str8(Malformed8Strings[i].m8);
        bool err;
        EXPECT_EQ(HashUTF8AsUTF16(str8.get(), str8.Length(), &err), 0u);
        EXPECT_TRUE(err);
      }
    }

    /**
     * This tests the handling of a non-ascii character at various locations in a
     * UTF-16 string that is being converted to UTF-8.
     */
    static void NonASCII16_helper(const size_t aStrSize) {
      const size_t kTestSize = aStrSize;
      const size_t kMaxASCII = 0x80;
      const char16_t kUTF16Char = 0xC9;
      const char kUTF8Surrogates[] = {char(0xC3), char(0x89)};

      // Generate a string containing only ASCII characters.
      nsString asciiString;
      asciiString.SetLength(kTestSize);
      nsCString asciiCString;
      asciiCString.SetLength(kTestSize);

      auto str_buff = asciiString.BeginWriting();
      auto cstr_buff = asciiCString.BeginWriting();
      for (size_t i = 0; i < kTestSize; i++) {
        str_buff[i] = i % kMaxASCII;
        cstr_buff[i] = i % kMaxASCII;
      }

      // Now go through and test conversion when exactly one character will
      // result in a multibyte sequence.
      for (size_t i = 0; i < kTestSize; i++) {
        // Setup the UTF-16 string.
        nsString unicodeString(asciiString);
        auto buff = unicodeString.BeginWriting();
        buff[i] = kUTF16Char;

        // Do the conversion, make sure the length increased by 1.
        nsCString dest;
        AppendUTF16toUTF8(unicodeString, dest);
        EXPECT_EQ(dest.Length(), unicodeString.Length() + 1);

        // Build up the expected UTF-8 string.
        nsCString expected;

        // First add the leading ASCII chars.
        expected.Append(asciiCString.BeginReading(), i);

        // Now append the UTF-8 pair we expect the UTF-16 unicode char to
        // be converted to.
        for (auto& c : kUTF8Surrogates) {
          expected.Append(c);
        }

        // And finish with the trailing ASCII chars.
        expected.Append(asciiCString.BeginReading() + i + 1, kTestSize - i - 1);

        EXPECT_STREQ(dest.BeginReading(), expected.BeginReading());
      }
    }

    TEST(UTF, NonASCII16)
    {
      // Test with various string sizes to catch any special casing.
      NonASCII16_helper(1);
      NonASCII16_helper(8);
      NonASCII16_helper(16);
      NonASCII16_helper(32);
      NonASCII16_helper(512);
    }

    TEST(UTF, UTF8CharEnumerator)
    {
      const char* p =
          "\x61\xC0\xC2\xC2\x80\xE0\x80\x80\xE0\xA0\x80\xE1\x80\x80\xED\xBF\xBF\xED"
          "\x9F\xBF\xEE\x80\x80\xEE\x80\xFF\xF0\x90\x80\x80\xF0\x80\x80\x80\xF1\x80"
          "\x80\x80\xF4\x8F\xBF\xF4\x8F\xBF\xBF\xF4\xBF\xBF\xBF";
      const char* end = p + 49;
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0x0061U);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0x0080U);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0x0800U);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0x1000U);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xD7FFU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xE000U);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0x10000U);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0x40000U);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0x10FFFFU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(p, end);
      p = "\xC2\xB6";
      end = p + 1;
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(p, end);
      p = "\xE2\x98\x83";
      end = p + 2;
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(p, end);
      p = "\xF0\x9F\x92\xA9";
      end = p + 2;
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(p, end);
      p = "\xF0\x9F\x92\xA9";
      end = p + 3;
      EXPECT_EQ(UTF8CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(p, end);
    }

    TEST(UTF, UTF16CharEnumerator)
    {
      const char16_t* p = u"\u0061\U0001F4A9";
      const char16_t* end = p + 3;
      EXPECT_EQ(UTF16CharEnumerator::NextChar(&p, end), 0x0061U);
      EXPECT_EQ(UTF16CharEnumerator::NextChar(&p, end), 0x1F4A9U);
      EXPECT_EQ(p, end);
      const char16_t loneHigh = 0xD83D;
      p = &loneHigh;
      end = p + 1;
      EXPECT_EQ(UTF16CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(p, end);
      const char16_t loneLow = 0xDCA9;
      p = &loneLow;
      end = p + 1;
      EXPECT_EQ(UTF16CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(p, end);
      const char16_t loneHighStr[] = {0xD83D, 0x0061};
      p = loneHighStr;
      end = p + 2;
      EXPECT_EQ(UTF16CharEnumerator::NextChar(&p, end), 0xFFFDU);
      EXPECT_EQ(UTF16CharEnumerator::NextChar(&p, end), 0x0061U);
      EXPECT_EQ(p, end);
    }

    }  // namespace TestUTF