# Global Metrics

path: .metrics.cyclomatic.sum
old: 103.0
new: 5.0
path: .metrics.cyclomatic.average
old: 3.433333333333333
new: 1.0
path: .metrics.halstead.N1
old: 1289.0
new: 472.0
path: .metrics.halstead.bugs
old: 3.2491418289929848
new: 1.1160182289269422
path: .metrics.halstead.vocabulary
old: 374.0
new: 101.0
path: .metrics.halstead.estimated_program_length
old: 3022.405585786558
new: 613.8390530476457
path: .metrics.halstead.effort
old: 962354.0668190572
new: 193726.4029281486
path: .metrics.halstead.n2
old: 337.0
new: 87.0
path: .metrics.halstead.volume
old: 18931.37122865112
new: 5872.542527787083
path: .metrics.halstead.purity_ratio
old: 1.3645171944860306
new: 0.6959626451787366
path: .metrics.halstead.length
old: 2215.0
new: 882.0
path: .metrics.halstead.n1
old: 37.0
new: 14.0
path: .metrics.halstead.level
old: 0.019671939758332847
new: 0.030313588850174215
path: .metrics.halstead.N2
old: 926.0
new: 410.0
path: .metrics.halstead.difficulty
old: 50.83382789317507
new: 32.98850574712644
path: .metrics.halstead.time
old: 53464.114823280965
new: 10762.5779404527
path: .metrics.mi.mi_original
old: -8.729545488861334
new: 38.89143527844588
path: .metrics.mi.mi_sei
old: -56.34152515450637
new: 2.7398735036488233
path: .metrics.mi.mi_visual_studio
old: 0.0
new: 22.743529402599933
path: .metrics.loc.cloc
old: 53.0
new: 17.0
path: .metrics.loc.sloc
old: 646.0
new: 200.0
path: .metrics.loc.blank
old: 107.0
new: 38.0
path: .metrics.loc.lloc
old: 230.0
new: 68.0
path: .metrics.loc.ploc
old: 486.0
new: 145.0
path: .metrics.nexits.average
old: 0.9333333333333332
new: 0.0
path: .metrics.nexits.sum
old: 28.0
new: 0.0
path: .metrics.nargs.average
old: 1.1666666666666667
new: 2.0
path: .metrics.nargs.sum
old: 35.0
new: 8.0
path: .metrics.nom.functions
old: 28.0
new: 4.0
path: .metrics.nom.total
old: 30.0
new: 4.0
path: .metrics.nom.closures
old: 2.0
new: 0.0
path: .metrics.cognitive.average
old: 3.1666666666666665
new: 0.0
path: .metrics.cognitive.sum
old: 95.0
new: 0.0

# Spaces Data

## Minimal test - lines (179, 200)

path: .spaces[3].metrics.halstead.N1
old: 48.0
new: 49.0
path: .spaces[3].metrics.halstead.N2
old: 35.0
new: 49.0
path: .spaces[3].metrics.halstead.vocabulary
old: 27.0
new: 29.0
path: .spaces[3].metrics.halstead.purity_ratio
old: 1.224372396900984
new: 1.2016222455553445
path: .spaces[3].metrics.halstead.length
old: 83.0
new: 98.0
path: .spaces[3].metrics.halstead.time
old: 479.61625672864153
new: 206.18203683108356
path: .spaces[3].metrics.halstead.estimated_program_length
old: 101.62290894278166
new: 117.75898006442377
path: .spaces[3].metrics.halstead.difficulty
old: 21.875
new: 7.795454545454546
path: .spaces[3].metrics.halstead.n2
old: 12.0
new: 22.0
path: .spaces[3].metrics.halstead.level
old: 0.045714285714285714
new: 0.1282798833819242
path: .spaces[3].metrics.halstead.n1
old: 15.0
new: 7.0
path: .spaces[3].metrics.halstead.bugs
old: 0.14027803665454325
new: 0.07990261001621618
path: .spaces[3].metrics.halstead.volume
old: 394.65566267956785
new: 476.082137522502
path: .spaces[3].metrics.halstead.effort
old: 8633.092621115547
new: 3711.276662959504
path: .spaces[3].metrics.nexits.sum
old: 1.0
new: 0.0
path: .spaces[3].metrics.nexits.average
old: 1.0
new: 0.0
path: .spaces[3].metrics.mi.mi_visual_studio
old: 51.71305423959054
new: 51.83277321072231
path: .spaces[3].metrics.mi.mi_sei
old: 85.23732412156556
new: 52.27286098933136
path: .spaces[3].metrics.mi.mi_original
old: 88.42932274969982
new: 88.63404219033515
path: .spaces[3].metrics.nargs.average
old: 1.0
new: 2.0
path: .spaces[3].metrics.nargs.sum
old: 1.0
new: 2.0
path: .spaces[3].metrics.loc.ploc
old: 15.0
new: 16.0
path: .spaces[3].metrics.loc.cloc
old: 5.0
new: 0.0
path: .spaces[3].metrics.loc.blank
old: 3.0
new: 6.0
path: .spaces[3].metrics.loc.sloc
old: 23.0
new: 22.0
path: .spaces[3].metrics.loc.lloc
old: 9.0
new: 6.0
path: .spaces[3].metrics.cyclomatic.average
old: 3.0
new: 1.0
path: .spaces[3].metrics.cyclomatic.sum
old: 3.0
new: 1.0
path: .spaces[3].metrics.cognitive.sum
old: 3.0
new: 0.0
path: .spaces[3].metrics.cognitive.average
old: 3.0
new: 0.0

### Code

    TEST(SeekableStreamWrapper, Interfaces)
    {
      nsCOMPtr reader;
      nsCOMPtr writer;

      NewSeekablePipe(getter_AddRefs(reader), getter_AddRefs(writer));

      nsCOMPtr readerType1 = do_QueryInterface(reader);
      EXPECT_TRUE(readerType1);

      nsCOMPtr readerType2 = do_QueryInterface(reader);
      EXPECT_TRUE(readerType2);

      nsCOMPtr readerType3 = do_QueryInterface(reader);
      EXPECT_TRUE(readerType3);

      nsCOMPtr readerType4 = do_QueryInterface(reader);
      EXPECT_TRUE(readerType4);

      nsCOMPtr readerType5 = do_QueryInterface(reader);
      EXPECT_TRUE(readerType5);
    }

## Minimal test - lines (13, 32)

path: .spaces[0].metrics.halstead.volume
old: 27.0
new: 516.9925001442313
path: .spaces[0].metrics.halstead.estimated_program_length
old: 16.36452797660028
new: 154.1501525493784
path: .spaces[0].metrics.halstead.time
old: 3.75
new: 303.30226675128233
path: .spaces[0].metrics.halstead.n2
old: 3.0
new: 25.0
path: .spaces[0].metrics.halstead.vocabulary
old: 8.0
new: 36.0
path: .spaces[0].metrics.halstead.n1
old: 5.0
new: 11.0
path: .spaces[0].metrics.halstead.bugs
old: 0.005526047247960579
new: 0.10335008846740668
path: .spaces[0].metrics.halstead.length
old: 9.0
new: 100.0
path: .spaces[0].metrics.halstead.N2
old: 3.0
new: 48.0
path: .spaces[0].metrics.halstead.purity_ratio
old: 1.81828088628892
new: 1.5415015254937838
path: .spaces[0].metrics.halstead.effort
old: 67.5
new: 5459.440801523082
path: .spaces[0].metrics.halstead.level
old: 0.4
new: 0.0946969696969697
path: .spaces[0].metrics.halstead.N1
old: 6.0
new: 52.0
path: .spaces[0].metrics.halstead.difficulty
old: 2.5
new: 10.56
path: .spaces[0].metrics.loc.blank
old: 0.0
new: 4.0
path: .spaces[0].metrics.loc.ploc
old: 1.0
new: 16.0
path: .spaces[0].metrics.loc.sloc
old: 1.0
new: 20.0
path: .spaces[0].metrics.loc.lloc
old: 1.0
new: 6.0
path: .spaces[0].metrics.mi.mi_visual_studio
old: 89.84306917940205
new: 52.485023190222854
path: .spaces[0].metrics.mi.mi_sei
old: 146.04458498874996
new: 53.881967245876965
path: .spaces[0].metrics.mi.mi_original
old: 153.6316482967775
new: 89.74938965528109
path: .spaces[0].metrics.nargs.sum
old: 0.0
new: 2.0
path: .spaces[0].metrics.nargs.average
old: 0.0
new: 2.0

### Code

    static void NewSeekablePipe(nsIInputStream** aReader,
                                nsIOutputStream** aWriter) {
      nsCOMPtr reader;
      nsCOMPtr writer;

      nsresult rv =
          NS_NewPipe2(getter_AddRefs(reader), getter_AddRefs(writer), true, true);
      ASSERT_TRUE(NS_SUCCEEDED(rv));

      nsCOMPtr seekable = do_QueryInterface(reader);
      EXPECT_FALSE(seekable);

      nsCOMPtr wrapped;
      rv = mozilla::SeekableStreamWrapper::MaybeWrap(do_AddRef(reader),
                                                     getter_AddRefs(wrapped));
      ASSERT_TRUE(NS_SUCCEEDED(rv));

      wrapped.forget(aReader);
      writer.forget(aWriter);
    }

## Minimal test - lines (54, 177)

path: .spaces[2].metrics.mi.mi_original
old: 62.9017111428782
new: 50.09483872799278
path: .spaces[2].metrics.mi.mi_sei
old: 43.811604942127886
new: 19.847124776713205
path: .spaces[2].metrics.mi.mi_visual_studio
old: 36.78462639934398
new: 29.29522732631157
path: .spaces[2].metrics.loc.lloc
old: 24.0
new: 50.0
path: .spaces[2].metrics.loc.ploc
old: 47.0
new: 93.0
path: .spaces[2].metrics.loc.cloc
old: 9.0
new: 12.0
path: .spaces[2].metrics.loc.sloc
old: 64.0
new: 124.0
path: .spaces[2].metrics.loc.blank
old: 8.0
new: 19.0
path: .spaces[2].metrics.halstead.estimated_program_length
old: 307.18795451213606
new: 387.8686140532334
path: .spaces[2].metrics.halstead.vocabulary
old: 61.0
new: 71.0
path: .spaces[2].metrics.halstead.effort
old: 33984.96064864934
new: 107025.21545209024
path: .spaces[2].metrics.halstead.n1
old: 19.0
new: 13.0
path: .spaces[2].metrics.halstead.time
old: 1888.053369369408
new: 5945.845302893901
path: .spaces[2].metrics.halstead.N1
old: 133.0
new: 321.0
path: .spaces[2].metrics.halstead.difficulty
old: 23.97619047619047
new: 29.698275862068964
path: .spaces[2].metrics.halstead.level
old: 0.041708043694141016
new: 0.03367198838896952
path: .spaces[2].metrics.halstead.length
old: 239.0
new: 586.0
path: .spaces[2].metrics.halstead.N2
old: 106.0
new: 265.0
path: .spaces[2].metrics.halstead.n2
old: 42.0
new: 58.0
path: .spaces[2].metrics.halstead.volume
old: 1417.4462236775298
new: 3603.751812029744
path: .spaces[2].metrics.halstead.purity_ratio
old: 1.2853052490047534
new: 0.661891832855347
path: .spaces[2].metrics.halstead.bugs
old: 0.34973298357394106
new: 0.7513970502096325
path: .spaces[2].metrics.nexits.average
old: 4.0
new: 0.0
path: .spaces[2].metrics.nexits.sum
old: 4.0
new: 0.0
path: .spaces[2].metrics.cognitive.average
old: 9.0
new: 0.0
path: .spaces[2].metrics.cognitive.sum
old: 9.0
new: 0.0
path: .spaces[2].metrics.cyclomatic.sum
old: 13.0
new: 1.0
path: .spaces[2].metrics.cyclomatic.average
old: 6.5
new: 1.0

### Code

    TEST(SeekableStreamWrapper, WrapPipe)
    {
      nsCOMPtr reader;
      nsCOMPtr writer;

      NewSeekablePipe(getter_AddRefs(reader), getter_AddRefs(writer));

      nsTArray inputData;
      testing::CreateData(1024, inputData);

      uint32_t numWritten = 0;
      nsresult rv =
          writer->Write(inputData.Elements(), inputData.Length(), &numWritten);
      EXPECT_TRUE(NS_SUCCEEDED(rv));
      EXPECT_EQ(numWritten, 1024u);

      nsCOMPtr seekable = do_QueryInterface(reader);
      ASSERT_TRUE(seekable);

      nsCOMPtr cloneable = do_QueryInterface(reader);
      ASSERT_TRUE(cloneable);
      ASSERT_TRUE(cloneable->GetCloneable());

      nsCOMPtr clone1;
      rv = cloneable->Clone(getter_AddRefs(clone1));
      ASSERT_TRUE(NS_SUCCEEDED(rv));
      ASSERT_TRUE(clone1);

      // Check that we can read the first 512 bytes.
      {
        char buf[512];
        uint32_t numRead = 0;
        rv = reader->Read(buf, 512, &numRead);
        EXPECT_TRUE(NS_SUCCEEDED(rv));
        EXPECT_EQ(numRead, 512u);
        EXPECT_EQ(mozilla::Span(inputData).First(512), mozilla::Span(buf));
      }

      // Check that we can read the second 512 bytes.
      {
        char buf[512];
        uint32_t numRead = 0;
        rv = reader->Read(buf, 512, &numRead);
        EXPECT_TRUE(NS_SUCCEEDED(rv));
        EXPECT_EQ(numRead, 512u);
        EXPECT_EQ(mozilla::Span(inputData).Last(512), mozilla::Span(buf));
      }

      // Should be at the end of the pipe
      {
        char buf[1];
        uint32_t numRead = 0;
        rv = reader->Read(buf, 1, &numRead);
        EXPECT_EQ(rv, NS_BASE_STREAM_WOULD_BLOCK);
      }

      // Re-read the second 512 bytes by seeking back.
      {
        rv = seekable->Seek(nsISeekableStream::NS_SEEK_CUR, -512);
        EXPECT_TRUE(NS_SUCCEEDED(rv));

        char buf[512];
        uint32_t numRead = 0;
        rv = reader->Read(buf, 512, &numRead);
        EXPECT_TRUE(NS_SUCCEEDED(rv));
        EXPECT_EQ(numRead, 512u);
        EXPECT_EQ(mozilla::Span(inputData).Last(512), mozilla::Span(buf));
      }

      // Re-read the last 256 bytes by seeking absolutely
      {
        rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, 768);
        EXPECT_TRUE(NS_SUCCEEDED(rv));

        char buf[256];
        uint32_t numRead = 0;
        rv = reader->Read(buf, 256, &numRead);
        EXPECT_TRUE(NS_SUCCEEDED(rv));
        EXPECT_EQ(numRead, 256u);
        EXPECT_EQ(mozilla::Span(inputData).Last(256), mozilla::Span(buf));
      }

      // Double-check that we haven't impacted our clone
      {
        char buf[1024];
        uint32_t numRead = 0;
        rv = clone1->Read(buf, 1024, &numRead);
        EXPECT_TRUE(NS_SUCCEEDED(rv));
        EXPECT_EQ(numRead, 1024u);
        EXPECT_EQ(mozilla::Span(inputData), mozilla::Span(buf));
      }

      // The clone should no longer be seekable once closed.
      rv = clone1->Close();
      EXPECT_TRUE(NS_SUCCEEDED(rv));
      nsCOMPtr clone1Seekable(do_QueryInterface(clone1));
      rv = clone1Seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);
      EXPECT_TRUE(NS_FAILED(rv));

      // Should still be open
      {
        uint64_t available = 0;
        rv = reader->Available(&available);
        EXPECT_TRUE(NS_SUCCEEDED(rv));
        EXPECT_EQ(available, uint64_t(0));
      }

      // Close the original output stream
      rv = writer->Close();
      EXPECT_TRUE(NS_SUCCEEDED(rv));

      // Should be closed
      {
        uint64_t available = 0;
        rv = reader->Available(&available);
        EXPECT_EQ(rv, NS_BASE_STREAM_CLOSED);
      }

      // Seeing back to the beginning should re-open the stream which had reached
      // the end.
      rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);
      EXPECT_TRUE(NS_SUCCEEDED(rv));
      testing::ConsumeAndValidateStream(reader, inputData);
    }

## Minimal test - lines (34, 52)

path: .spaces[1].metrics.halstead.length
old: 62.0
new: 94.0
path: .spaces[1].metrics.halstead.bugs
old: 0.06607094343959774
new: 0.08736219505784243
path: .spaces[1].metrics.halstead.n1
old: 12.0
new: 10.0
path: .spaces[1].metrics.halstead.level
old: 0.10317460317460318
new: 0.11363636363636365
path: .spaces[1].metrics.halstead.purity_ratio
old: 1.4697623603949688
new: 1.5884647414174653
path: .spaces[1].metrics.halstead.N2
old: 21.0
new: 44.0
path: .spaces[1].metrics.halstead.n2
old: 13.0
new: 25.0
path: .spaces[1].metrics.halstead.time
old: 155.0333527970946
new: 235.71905064538203
path: .spaces[1].metrics.halstead.vocabulary
old: 25.0
new: 35.0
path: .spaces[1].metrics.halstead.N1
old: 41.0
new: 50.0
path: .spaces[1].metrics.halstead.volume
old: 287.9190837660329
new: 482.1526035928269
path: .spaces[1].metrics.halstead.difficulty
old: 9.692307692307692
new: 8.8
path: .spaces[1].metrics.halstead.effort
old: 2790.600350347703
new: 4242.942911616877
path: .spaces[1].metrics.halstead.estimated_program_length
old: 91.12526634448808
new: 149.31568569324173
path: .spaces[1].metrics.loc.sloc
old: 25.0
new: 19.0
path: .spaces[1].metrics.loc.lloc
old: 16.0
new: 6.0
path: .spaces[1].metrics.loc.blank
old: 5.0
new: 4.0
path: .spaces[1].metrics.loc.ploc
old: 20.0
new: 15.0
path: .spaces[1].metrics.nargs.average
old: 1.0
new: 2.0
path: .spaces[1].metrics.nargs.sum
old: 1.0
new: 2.0
path: .spaces[1].metrics.cognitive.sum
old: 1.0
new: 0.0
path: .spaces[1].metrics.cognitive.average
old: 1.0
new: 0.0
path: .spaces[1].metrics.cyclomatic.average
old: 5.0
new: 1.0
path: .spaces[1].metrics.cyclomatic.sum
old: 5.0
new: 1.0
path: .spaces[1].metrics.nexits.average
old: 1.0
new: 0.0
path: .spaces[1].metrics.nexits.sum
old: 1.0
new: 0.0
path: .spaces[1].metrics.mi.mi_original
old: 88.25827833326333
new: 90.94313305919144
path: .spaces[1].metrics.mi.mi_sei
old: 52.1380277738064
new: 55.60417493479237
path: .spaces[1].metrics.mi.mi_visual_studio
old: 51.61302826506627
new: 53.18311874806518

### Code

    TEST(SeekableStreamWrapper, NoWrap)
    {
      nsTArray inputData;
      testing::CreateData(4096, inputData);
      nsDependentCSubstring inputString(inputData.Elements(), inputData.Length());

      nsCOMPtr stream;
      nsresult rv = NS_NewCStringInputStream(getter_AddRefs(stream), inputString);
      ASSERT_TRUE(NS_SUCCEEDED(rv));

      nsCOMPtr wrapped;
      rv = mozilla::SeekableStreamWrapper::MaybeWrap(do_AddRef(stream),
                                                     getter_AddRefs(wrapped));
      ASSERT_TRUE(NS_SUCCEEDED(rv));

      EXPECT_EQ(stream, wrapped);

      testing::ConsumeAndValidateStream(wrapped, inputString);
    }