# Global Metrics

path: .metrics.cognitive.average
old: null
new: 0.0
path: .metrics.loc.cloc
old: 18.0
new: 6.0
path: .metrics.loc.blank
old: 13.0
new: 56.0
path: .metrics.loc.ploc
old: 25.0
new: 204.0
path: .metrics.loc.sloc
old: 56.0
new: 266.0
path: .metrics.loc.lloc
old: 0.0
new: 111.0
path: .metrics.nargs.average
old: null
new: 1.8666666666666667
path: .metrics.nargs.sum
old: 0.0
new: 28.0
path: .metrics.mi.mi_original
old: 76.56258754391646
new: 29.858228916783048
path: .metrics.mi.mi_visual_studio
old: 44.77344300813828
new: 17.46095258291406
path: .metrics.mi.mi_sei
old: 73.44230485609262
new: -19.364774751221113
path: .metrics.cyclomatic.sum
old: 2.0
new: 17.0
path: .metrics.nexits.average
old: null
new: 0.0
path: .metrics.halstead.n1
old: 6.0
new: 14.0
path: .metrics.halstead.N1
old: 24.0
new: 707.0
path: .metrics.halstead.bugs
old: 0.029170083827534218
new: 2.035682837942706
path: .metrics.halstead.level
old: 0.30864197530864196
new: 0.01691065118626956
path: .metrics.halstead.estimated_program_length
old: 131.60617974869504
new: 459.7309446694772
path: .metrics.halstead.effort
old: 818.6313983283272
new: 477251.2285171488
path: .metrics.halstead.N2
old: 27.0
new: 566.0
path: .metrics.halstead.time
old: 45.47952212935152
new: 26513.957139841597
path: .metrics.halstead.vocabulary
old: 31.0
new: 81.0
path: .metrics.halstead.purity_ratio
old: 2.580513328405785
new: 0.3611397837152217
path: .metrics.halstead.difficulty
old: 3.24
new: 59.134328358208954
path: .metrics.halstead.length
old: 51.0
new: 1273.0
path: .metrics.halstead.volume
old: 252.6640118297306
new: 8070.629053672127
path: .metrics.halstead.n2
old: 25.0
new: 67.0
path: .metrics.nom.total
old: 0.0
new: 15.0
path: .metrics.nom.functions
old: 0.0
new: 15.0

# Spaces Data

## Minimal test - lines (18, 266)

path: .spaces[0].metrics.cyclomatic.sum
old: 1.0
new: 16.0
path: .spaces[0].metrics.cognitive.average
old: null
new: 0.0
path: .spaces[0].metrics.mi.mi_visual_studio
old: 56.77570639661327
new: 18.313126037646768
path: .spaces[0].metrics.mi.mi_sei
old: 64.46711927232033
new: -28.893096280295637
path: .spaces[0].metrics.mi.mi_original
old: 97.0864579382087
new: 31.315445524375978
path: .spaces[0].metrics.halstead.volume
old: 209.2150500951926
new: 7830.128066983222
path: .spaces[0].metrics.halstead.N2
old: 23.0
new: 558.0
path: .spaces[0].metrics.halstead.vocabulary
old: 27.0
new: 73.0
path: .spaces[0].metrics.halstead.purity_ratio
old: 2.493571274646758
new: 0.3165050662617827
path: .spaces[0].metrics.halstead.N1
old: 21.0
new: 707.0
path: .spaces[0].metrics.halstead.n1
old: 5.0
new: 14.0
path: .spaces[0].metrics.halstead.length
old: 44.0
new: 1265.0
path: .spaces[0].metrics.halstead.difficulty
old: 2.613636363636364
new: 66.20338983050847
path: .spaces[0].metrics.halstead.effort
old: 546.8120627487989
new: 518381.020841296
path: .spaces[0].metrics.halstead.estimated_program_length
old: 109.71713608445737
new: 400.3789088211551
path: .spaces[0].metrics.halstead.n2
old: 22.0
new: 59.0
path: .spaces[0].metrics.halstead.bugs
old: 0.022289695537484423
new: 2.151021775995036
path: .spaces[0].metrics.halstead.level
old: 0.3826086956521738
new: 0.015104966717869943
path: .spaces[0].metrics.halstead.time
old: 30.37844793048883
new: 28798.94560229422
path: .spaces[0].metrics.nargs.average
old: null
new: 1.8666666666666667
path: .spaces[0].metrics.nargs.sum
old: 0.0
new: 28.0
path: .spaces[0].metrics.nom.functions
old: 0.0
new: 15.0
path: .spaces[0].metrics.nom.total
old: 0.0
new: 15.0
path: .spaces[0].metrics.loc.ploc
old: 16.0
new: 194.0
path: .spaces[0].metrics.loc.blank
old: 1.0
new: 55.0
path: .spaces[0].metrics.loc.sloc
old: 17.0
new: 249.0
path: .spaces[0].metrics.loc.lloc
old: 0.0
new: 111.0
path: .spaces[0].metrics.nexits.average
old: null
new: 0.0

### Code

    namespace TestMoveString {

    #define NEW_VAL "**new value**"
    #define OLD_VAL "old value"

    typedef mozilla::detail::StringDataFlags Df;

    static void SetAsOwned(nsACString& aStr, const char* aValue) {
      size_t len = strlen(aValue);
      char* data = new char[len + 1];
      memcpy(data, aValue, len + 1);
      aStr.Adopt(data, len);
      EXPECT_EQ(aStr.GetDataFlags(), Df::OWNED | Df::TERMINATED);
      EXPECT_STREQ(aStr.BeginReading(), aValue);
    }

    static void ExpectTruncated(const nsACString& aStr) {
      EXPECT_EQ(aStr.Length(), uint32_t(0));
      EXPECT_STREQ(aStr.BeginReading(), "");
      EXPECT_EQ(aStr.GetDataFlags(), Df::TERMINATED);
    }

    static void ExpectNew(const nsACString& aStr) {
      EXPECT_EQ(aStr.Length(), strlen(NEW_VAL));
      EXPECT_TRUE(aStr.EqualsASCII(NEW_VAL));
    }

    TEST(MoveString, SharedIntoOwned)
    {
      nsCString out;
      SetAsOwned(out, OLD_VAL);
      EXPECT_EQ(out.GetDataFlags(), Df::OWNED | Df::TERMINATED);

      nsCString in;
      in.Assign(NEW_VAL);
      EXPECT_EQ(in.GetDataFlags(), Df::REFCOUNTED | Df::TERMINATED);
      const char* data = in.get();

      out.Assign(std::move(in));
      ExpectTruncated(in);
      ExpectNew(out);

      EXPECT_EQ(out.GetDataFlags(), Df::REFCOUNTED | Df::TERMINATED);
      EXPECT_EQ(out.get(), data);
    }

    TEST(MoveString, OwnedIntoOwned)
    {
      nsCString out;
      SetAsOwned(out, OLD_VAL);
      EXPECT_EQ(out.GetDataFlags(), Df::OWNED | Df::TERMINATED);

      nsCString in;
      SetAsOwned(in, NEW_VAL);
      EXPECT_EQ(in.GetDataFlags(), Df::OWNED | Df::TERMINATED);
      const char* data = in.get();

      out.Assign(std::move(in));
      ExpectTruncated(in);
      ExpectNew(out);

      EXPECT_EQ(out.GetDataFlags(), Df::OWNED | Df::TERMINATED);
      EXPECT_EQ(out.get(), data);
    }

    TEST(MoveString, LiteralIntoOwned)
    {
      nsCString out;
      SetAsOwned(out, OLD_VAL);
      EXPECT_EQ(out.GetDataFlags(), Df::OWNED | Df::TERMINATED);

      nsCString in;
      in.AssignLiteral(NEW_VAL);
      EXPECT_EQ(in.GetDataFlags(), Df::LITERAL | Df::TERMINATED);
      const char* data = in.get();

      out.Assign(std::move(in));
      ExpectTruncated(in);
      ExpectNew(out);

      EXPECT_EQ(out.GetDataFlags(), Df::LITERAL | Df::TERMINATED);
      EXPECT_EQ(out.get(), data);
    }

    TEST(MoveString, AutoIntoOwned)
    {
      nsCString out;
      SetAsOwned(out, OLD_VAL);
      EXPECT_EQ(out.GetDataFlags(), Df::OWNED | Df::TERMINATED);

      nsAutoCString in;
      in.Assign(NEW_VAL);
      EXPECT_EQ(in.GetDataFlags(), Df::INLINE | Df::TERMINATED);
      const char* data = in.get();

      out.Assign(std::move(in));
      ExpectTruncated(in);
      ExpectNew(out);

      EXPECT_EQ(out.GetDataFlags(), Df::REFCOUNTED | Df::TERMINATED);
      EXPECT_NE(out.get(), data);
    }

    TEST(MoveString, DepIntoOwned)
    {
      nsCString out;
      SetAsOwned(out, OLD_VAL);
      EXPECT_EQ(out.GetDataFlags(), Df::OWNED | Df::TERMINATED);

      nsDependentCSubstring in(NEW_VAL "garbage after", strlen(NEW_VAL));
      EXPECT_EQ(in.GetDataFlags(), Df(0));

      out.Assign(std::move(in));
      ExpectTruncated(in);
      ExpectNew(out);

      EXPECT_EQ(out.GetDataFlags(), Df::REFCOUNTED | Df::TERMINATED);
    }

    TEST(MoveString, VoidIntoOwned)
    {
      nsCString out;
      SetAsOwned(out, OLD_VAL);
      EXPECT_EQ(out.GetDataFlags(), Df::OWNED | Df::TERMINATED);

      nsCString in = VoidCString();
      EXPECT_EQ(in.GetDataFlags(), Df::VOIDED | Df::TERMINATED);

      out.Assign(std::move(in));
      ExpectTruncated(in);

      EXPECT_EQ(out.Length(), 0u);
      EXPECT_STREQ(out.get(), "");
      EXPECT_EQ(out.GetDataFlags(), Df::VOIDED | Df::TERMINATED);
    }

    TEST(MoveString, SharedIntoAuto)
    {
      nsAutoCString out;
      out.Assign(OLD_VAL);
      EXPECT_EQ(out.GetDataFlags(), Df::INLINE | Df::TERMINATED);

      nsCString in;
      in.Assign(NEW_VAL);
      EXPECT_EQ(in.GetDataFlags(), Df::REFCOUNTED | Df::TERMINATED);
      const char* data = in.get();

      out.Assign(std::move(in));
      ExpectTruncated(in);
      ExpectNew(out);

      EXPECT_EQ(out.GetDataFlags(), Df::REFCOUNTED | Df::TERMINATED);
      EXPECT_EQ(out.get(), data);
    }

    TEST(MoveString, OwnedIntoAuto)
    {
      nsAutoCString out;
      out.Assign(OLD_VAL);
      EXPECT_EQ(out.GetDataFlags(), Df::INLINE | Df::TERMINATED);

      nsCString in;
      SetAsOwned(in, NEW_VAL);
      EXPECT_EQ(in.GetDataFlags(), Df::OWNED | Df::TERMINATED);
      const char* data = in.get();

      out.Assign(std::move(in));
      ExpectTruncated(in);
      ExpectNew(out);

      EXPECT_EQ(out.GetDataFlags(), Df::OWNED | Df::TERMINATED);
      EXPECT_EQ(out.get(), data);
    }

    TEST(MoveString, LiteralIntoAuto)
    {
      nsAutoCString out;
      out.Assign(OLD_VAL);
      EXPECT_EQ(out.GetDataFlags(), Df::INLINE | Df::TERMINATED);

      nsCString in;
      in.AssignLiteral(NEW_VAL);
      EXPECT_EQ(in.GetDataFlags(), Df::LITERAL | Df::TERMINATED);
      const char* data = in.get();

      out.Assign(std::move(in));
      ExpectTruncated(in);
      ExpectNew(out);

      EXPECT_EQ(out.GetDataFlags(), Df::LITERAL | Df::TERMINATED);
      EXPECT_EQ(out.get(), data);
    }

    TEST(MoveString, AutoIntoAuto)
    {
      nsAutoCString out;
      out.Assign(OLD_VAL);
      EXPECT_EQ(out.GetDataFlags(), Df::INLINE | Df::TERMINATED);

      nsAutoCString in;
      in.Assign(NEW_VAL);
      EXPECT_EQ(in.GetDataFlags(), Df::INLINE | Df::TERMINATED);
      const char* data = in.get();

      out.Assign(std::move(in));
      ExpectTruncated(in);
      ExpectNew(out);

      EXPECT_EQ(out.GetDataFlags(), Df::INLINE | Df::TERMINATED);
      EXPECT_NE(out.get(), data);
    }

    TEST(MoveString, DepIntoAuto)
    {
      nsAutoCString out;
      out.Assign(OLD_VAL);
      EXPECT_EQ(out.GetDataFlags(), Df::INLINE | Df::TERMINATED);

      nsDependentCSubstring in(NEW_VAL "garbage after", strlen(NEW_VAL));
      EXPECT_EQ(in.GetDataFlags(), Df(0));

      out.Assign(std::move(in));
      ExpectTruncated(in);
      ExpectNew(out);

      EXPECT_EQ(out.GetDataFlags(), Df::INLINE | Df::TERMINATED);
    }

    TEST(MoveString, VoidIntoAuto)
    {
      nsAutoCString out;
      out.Assign(OLD_VAL);
      EXPECT_EQ(out.GetDataFlags(), Df::INLINE | Df::TERMINATED);

      nsCString in = VoidCString();
      EXPECT_EQ(in.GetDataFlags(), Df::VOIDED | Df::TERMINATED);

      out.Assign(std::move(in));
      ExpectTruncated(in);

      EXPECT_EQ(out.Length(), 0u);
      EXPECT_STREQ(out.get(), "");
      EXPECT_EQ(out.GetDataFlags(), Df::VOIDED | Df::TERMINATED);
    }

    #undef NEW_VAL
    #undef OLD_VAL

    }  // namespace TestMoveString