module("Aural.Utils.Sfz");

test('parse most basic', function() {
	var sfz = '\r\n//some file\r\n' + 
	'<region>\r\n' + 
	'sample=SOUND_1.wav \r\n' + 
	'pitch_keycenter=74\r\n' + 
	'lokey=72 hikey=76\r\n' + 
	'lovel=0 hivel=127\r\n\r\n\r\n' + 
	'<region>sample=SOUND_2.wav\r\n' + 
	'pitch_keycenter=C5\r\n' + 
	'lokey=77 hikey=81 //sample=machin\r\n' + 
	'lovel=0 hivel=127\r\n';

	var sfzFile = Aural.Utils.Sfz.File.loadFromString(sfz);

	equal(sfzFile.regions.length, 2, 'there should be 2 regions loaded');

	equal(sfzFile.regions[0].sample, 'SOUND_1.wav');
	equal(sfzFile.regions[0].pitchKeyCenter, 74);
	equal(sfzFile.regions[0].loKey, 72);
	equal(sfzFile.regions[0].hiKey, 76);
	equal(sfzFile.regions[0].loVelocity, 0);
	equal(sfzFile.regions[0].hiVelocity, 127);

	equal(sfzFile.regions[1].sample, 'SOUND_2.wav');
	equal(sfzFile.regions[1].pitchKeyCenter, 72);
	equal(sfzFile.regions[1].loKey, 77);
	equal(sfzFile.regions[1].hiKey, 81);
	equal(sfzFile.regions[1].loVelocity, 0);
	equal(sfzFile.regions[1].hiVelocity, 127);
});

test('parse groups', function() {
	var sfz = '\r\n//some file\r\n' + 
	'<region>sample=SOUND_1.wav\r\n' + 
	'<group>pitch_keycenter=50\r\n' +
	'<region>sample=SOUND_2.wav\r\n' + 
	'<region>sample=SOUND_2.wav\r\n' + 
	'<group>pitch_keycenter=51\r\n' +
	'<region>sample=SOUND_2.wav\r\n' + 
	'<region>sample=SOUND_2.wav pitch_keycenter=52';

	var sfzFile = Aural.Utils.Sfz.File.loadFromString(sfz);

	equal(sfzFile.regions.length, 5, 'there should be 5 regions loaded');

	equal(sfzFile.regions[0].pitchKeyCenter, 60);
	equal(sfzFile.regions[1].pitchKeyCenter, 50);
	equal(sfzFile.regions[2].pitchKeyCenter, 50);
	equal(sfzFile.regions[3].pitchKeyCenter, 51);
	equal(sfzFile.regions[4].pitchKeyCenter, 52);
});

test('parse ignore region without sample', function() {
	var sfz = '\r\n//some file\r\n' + 
	'<region>sample=SOUND_1.WAV pitch_keycenter=49\r\n' + 
	'<region>pitch_keycenter=50\r\n' + 
	'<group>sample=SOUND_1.WAV\r\n' +
	'<region>pitch_keycenter=51\r\n';

	var sfzFile = Aural.Utils.Sfz.File.loadFromString(sfz);

	equal(sfzFile.regions.length, 2, 'there should be 2 regions loaded');

	equal(sfzFile.regions[0].pitchKeyCenter, 49);
	equal(sfzFile.regions[1].pitchKeyCenter, 51);
});
@@ -2216,12 +2216,478 @@
 er, 51);%0A%7D);
+%0A%0Atest('parse sample with spaces', function() %7B%0A%09var sfz = '%3Cregion%3Esample=/files/My new sample1.wav%5Cr%5Cn' +%0A%09'pitch_keycenter=20%5Cr%5Cn' +%0A%09'%3Cregion%3Esample=/files/My new sample2.wav pitch_keycenter=21%5Cr%5Cn';%0A%0A%09var sfzFile = Aural.Utils.Sfz.File.loadFromString(sfz);%0A%0A%09equal(sfzFile.regions.length, 2, 'there should be 2 regions loaded');%0A%0A%09equal(sfzFile.regions%5B0%5D.sample, '/files/My new sample1.wav');%0A%09equal(sfzFile.regions%5B1%5D.sample, '/files/My new sample2.wav');%0A%7D);

Add a new test case highlighting a flaw in the SFZ parsing