Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null/undefined lyrics which cause exporter to fail #1026

Merged
merged 2 commits into from
Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src.csharp/AlphaTab.Test/Test/Globals.cs
Original file line number Diff line number Diff line change
@@ -87,7 +87,14 @@ public void ToBeTrue()

public void ToBeFalsy()
{
Assert.AreEqual(default!, _actual, _message);
if (_actual is string s)
{
Assert.IsTrue(string.IsNullOrEmpty(s), _message);
}
else
{
Assert.AreEqual(default!, _actual, _message);
}
}

public void ToThrowError(Type expected)
Original file line number Diff line number Diff line change
@@ -68,7 +68,12 @@ public class Expector<T> {
}

public fun toBeFalsy() {
kotlin.test.assertNull(_actual, _message)
val actual = _actual;
if(actual is String){
kotlin.test.assertTrue(actual.isEmpty(), _message)
} else {
kotlin.test.assertNull(_actual, _message)
}
}

public fun toThrowError(expected: KClass<out Exception>) {
Original file line number Diff line number Diff line change
@@ -39,6 +39,10 @@ public class List<T> : Iterable<T> {
_data.add(item)
}

public fun fill(item: T) {
_data.fill(item)
}

public fun push(items: List<T>) {
_data.addAll(items._data)
}
1 change: 1 addition & 0 deletions src/model/Track.ts
Original file line number Diff line number Diff line change
@@ -102,6 +102,7 @@ export class Track {
// initialize lyrics list for beat if required
if (!beat.lyrics) {
beat.lyrics = new Array<string>(lyrics.length);
beat.lyrics.fill("");
}
// assign chunk
beat.lyrics[li] = lyric.chunks[ci];
Binary file added test-data/guitarpro7/lyrics-null.gp
Binary file not shown.
18 changes: 12 additions & 6 deletions test/exporter/Gp7Exporter.test.ts
Original file line number Diff line number Diff line change
@@ -14,8 +14,7 @@ describe('Gp7ExporterTest', () => {
const data = await TestPlatform.loadFile('test-data/' + name);
try {
return ScoreLoader.loadScoreFromBytes(data);
}
catch (e) {
} catch (e) {
return null;
}
};
@@ -30,7 +29,10 @@ describe('Gp7ExporterTest', () => {
return new Gp7Exporter().export(score, null);
};

const testRoundTripEqual: (name: string, ignoreKeys: string[] | null) => Promise<void> = async (name: string, ignoreKeys: string[] | null = null): Promise<void> => {
const testRoundTripEqual: (name: string, ignoreKeys: string[] | null) => Promise<void> = async (
name: string,
ignoreKeys: string[] | null = null
): Promise<void> => {
try {
const expected = await loadScore(name);
if (!expected) {
@@ -42,7 +44,7 @@ describe('Gp7ExporterTest', () => {
const actual = prepareGp7ImporterWithBytes(exported).readScore();

const expectedJson = JsonConverter.scoreToJsObject(expected);
const actualJson = JsonConverter.scoreToJsObject(actual)
const actualJson = JsonConverter.scoreToJsObject(actual);

if (!ComparisonHelpers.expectJsonEqual(expectedJson, actualJson, '<' + fileName + '>', ignoreKeys)) {
await TestPlatform.saveFile(fileName, exported);
@@ -109,7 +111,7 @@ describe('Gp7ExporterTest', () => {
await testRoundTripEqual(`conversion/full-song.gpx`, [
'accidentalmode', // gets upgraded from default
'percussionarticulations', // gets added
'percussionarticulation', // gets added
'percussionarticulation' // gets added
]);
});

@@ -136,8 +138,12 @@ describe('Gp7ExporterTest', () => {
const actual = prepareGp7ImporterWithBytes(exported).readScore();

const expectedJson = JsonConverter.scoreToJsObject(expected);
const actualJson = JsonConverter.scoreToJsObject(actual)
const actualJson = JsonConverter.scoreToJsObject(actual);

ComparisonHelpers.expectJsonEqual(expectedJson, actualJson, '<alphatex>', ['accidentalmode']);
});

it('gp7-lyrics-null', async () => {
await testRoundTripEqual('guitarpro7/lyrics-null.gp', null);
});
});