Skip to content

Commit

Permalink
Merge pull request #1886 from andy840119/prevent-directly-assign-work…
Browse files Browse the repository at this point in the history
…ing-property

Prevent directly assign working property.
  • Loading branch information
andy840119 authored Mar 26, 2023
2 parents 942f59e + 11e8237 commit 9d16309
Show file tree
Hide file tree
Showing 27 changed files with 202 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,16 @@ private static void testNote(string expectedText, int expectedTone, bool expecte
[TestCase(0.3, 1, null)] // start + duration should not exceed 1
public void TestSliceNoteTime(double startPercentage, double durationPercentage, double[]? expected)
{
var lyric = new Lyric
var referencedLyric = new Lyric
{
TimeTags = TestCaseTagHelper.ParseTimeTags(new[] { "[0,start]:1000", "[1,start]:4000" }),
};

// start time will be 1000, and duration will be 3000.
var note = new Note
{
ReferenceLyric = lyric,
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric,
ReferenceTimeTagIndex = 0
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ public void TestUnlock()
[Test]
public void TestLockToReferenceLyric()
{
var referencedLyric = new Lyric { ID = 2 };

PrepareHitObject(new Lyric
{
Text = "カラオケ",
ReferenceLyric = new Lyric(),
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric,
ReferenceLyricConfig = new SyncLyricConfig(),
});

TriggerHandlerChangedWithChangeForbiddenException(c => c.Lock(LockState.Full));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ protected Lyric PrepareLyricWithSyncConfig(Lyric referencedLyric, IReferenceLyri
{
var lyric = new Lyric
{
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric,
ReferenceLyricConfig = config ?? new SyncLyricConfig()
};
Expand All @@ -22,4 +23,4 @@ protected Lyric PrepareLyricWithSyncConfig(Lyric referencedLyric, IReferenceLyri

return lyric;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,85 +13,88 @@ public partial class LyricReferenceChangeHandlerTest : LyricPropertyChangeHandle
[Test]
public void TestUpdateReferenceLyric()
{
var lyric = new Lyric
var referencedLyric = new Lyric
{
Text = "Referenced lyric"
};

PrepareHitObject(lyric, false);
PrepareHitObject(referencedLyric, false);

PrepareHitObject(new Lyric
{
Text = "I need the reference lyric."
});

TriggerHandlerChanged(c => c.UpdateReferenceLyric(lyric));
TriggerHandlerChanged(c => c.UpdateReferenceLyric(referencedLyric));

AssertSelectedHitObject(h =>
{
Assert.AreEqual(lyric, h.ReferenceLyric);
Assert.AreEqual(referencedLyric, h.ReferenceLyric);
Assert.IsTrue(h.ReferenceLyricConfig is ReferenceLyricConfig);
});
}

[Test]
public void TestSwitchToReferenceLyricConfig()
{
var lyric = new Lyric
var referencedLyric = new Lyric
{
Text = "Referenced lyric"
};

PrepareHitObject(new Lyric
{
Text = "Lyric",
ReferenceLyric = lyric
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric
});

TriggerHandlerChanged(c => c.SwitchToReferenceLyricConfig());

AssertSelectedHitObject(h =>
{
Assert.AreEqual(lyric, h.ReferenceLyric);
Assert.AreEqual(referencedLyric, h.ReferenceLyric);
Assert.IsTrue(h.ReferenceLyricConfig is ReferenceLyricConfig);
});
}

[Test]
public void TestSwitchToSyncLyricConfig()
{
var lyric = new Lyric
var referencedLyric = new Lyric
{
Text = "Referenced lyric"
};

PrepareHitObject(new Lyric
{
Text = "Lyric",
ReferenceLyric = lyric
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric
});

TriggerHandlerChanged(c => c.SwitchToSyncLyricConfig());

AssertSelectedHitObject(h =>
{
Assert.AreEqual(lyric, h.ReferenceLyric);
Assert.AreEqual(referencedLyric, h.ReferenceLyric);
Assert.IsTrue(h.ReferenceLyricConfig is SyncLyricConfig);
});
}

[Test]
public void TestAdjustLyricConfig()
{
var lyric = new Lyric
var referencedLyric = new Lyric
{
Text = "Referenced lyric"
};

PrepareHitObject(new Lyric
{
Text = "Lyric",
ReferenceLyric = lyric,
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric,
ReferenceLyricConfig = new SyncLyricConfig(),
});

Expand Down Expand Up @@ -126,4 +129,4 @@ public void TestWithReferenceLyric()
TriggerHandlerChanged(c => c.SwitchToSyncLyricConfig());
TriggerHandlerChanged(c => c.AdjustLyricConfig<SyncLyricConfig>(syncLyricConfig => syncLyricConfig.OffsetTime = 1000));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ public partial class NotesChangeHandlerTest : BaseHitObjectChangeHandlerTest<Not
[Test]
public void TestSplit()
{
var referencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "カラオケ", 1000, 1000);

PrepareHitObject(new Note
{
Text = "カラオケ",
ReferenceLyric = TestCaseNoteHelper.CreateLyricForNote("カラオケ", 1000, 1000)
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric
});

TriggerHandlerChanged(c => c.Split());
Expand Down Expand Up @@ -45,24 +48,26 @@ public void TestSplit()
[Test]
public void TestCombine()
{
var lyric = TestCaseNoteHelper.CreateLyricForNote("カラオケ", 1000, 1000);
var referencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "カラオケ", 1000, 1000);

// note that lyric and notes should in the selection.
PrepareHitObject(lyric);
PrepareHitObject(referencedLyric);
PrepareHitObjects(new[]
{
new Note
{
Text = "カラ",
RubyText = "から",
ReferenceLyric = lyric,
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric,
ReferenceTimeTagIndex = 0
},
new Note
{
Text = "オケ",
RubyText = "おけ",
ReferenceLyric = lyric,
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric,
ReferenceTimeTagIndex = 0
}
});
Expand All @@ -85,28 +90,30 @@ public void TestCombine()
[Test]
public void TestClear()
{
var lyric = new Lyric();
var referencedLyric = new Lyric { ID = 2 };

// note that lyric and notes should in the selection.
PrepareHitObject(lyric);
PrepareHitObject(referencedLyric);
PrepareHitObjects(new[]
{
new Note
{
Text = "カラ",
RubyText = "から",
ReferenceLyric = lyric,
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric,
},
new Note
{
Text = "オケ",
RubyText = "おけ",
ReferenceLyric = lyric,
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric,
}
}, false);

TriggerHandlerChanged(c => c.Clear());

AssertHitObjects(Assert.IsEmpty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public class CheckLyricReferenceLyricTest : HitObjectCheckTest<Lyric, CheckLyric
[Test]
public void TestCheck()
{
var referencedLyric = new Lyric();
var referencedLyric = new Lyric { ID = 2 };
var lyric = new Lyric
{
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric,
ReferenceLyricConfig = new ReferenceLyricConfig(),
};
Expand All @@ -34,6 +35,7 @@ public void TestCheckSelfReference()
ReferenceLyricConfig = new ReferenceLyricConfig(),
};

lyric.ReferenceLyricId = lyric.ID;
lyric.ReferenceLyric = lyric;

AssertNotOk<LyricIssue, IssueTemplateLyricSelfReference>(lyric);
Expand All @@ -42,9 +44,10 @@ public void TestCheckSelfReference()
[Test]
public void TestCheckInvalidReferenceLyric()
{
var referencedLyric = new Lyric();
var referencedLyric = new Lyric { ID = 2 };
var lyric = new Lyric
{
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric,
ReferenceLyricConfig = new ReferenceLyricConfig(),
};
Expand All @@ -55,9 +58,10 @@ public void TestCheckInvalidReferenceLyric()
[Test]
public void TestCheckNullReferenceLyricConfig()
{
var referencedLyric = new Lyric();
var referencedLyric = new Lyric { ID = 2 };
var lyric = new Lyric
{
ReferenceLyricId = referencedLyric.ID,
ReferenceLyric = referencedLyric,
};

Expand All @@ -75,4 +79,4 @@ public void TestCheckHasReferenceLyricConfigIfNoReferenceLyric()

AssertNotOk<LyricIssue, IssueTemplateLyricHasReferenceLyricConfigIfNoReferenceLyric>(lyric);
}
}
}
Loading

0 comments on commit 9d16309

Please sign in to comment.