Created
June 3, 2014 22:47
-
-
Save eka/e44489e7f552399d433e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_option_arguments(options) { | |
var installer_arguments = {}; | |
for(var i=0; i<options.length; i++) { | |
var option_arguments = options[i]; | |
var args = option_arguments.split(' '); | |
var regex = /\/(\w+)(=)?([0-9a-z-A-Z,]+)?/; | |
for(var j=0; j<args.length; j++) { | |
var arg = args[j]; | |
var match = regex.exec(arg); | |
var argument = match[1]; | |
var value = match[3]; | |
if(!value) { | |
installer_arguments[argument] = []; | |
} else { | |
var val = installer_arguments[argument] || []; | |
val.push(value); | |
installer_arguments[argument] = val; | |
} | |
} | |
} | |
var res = []; | |
for(var key in installer_arguments) { | |
var buf = ""; | |
buf += "/" + key; //installer_arguments[key] = installer_arguments[key].join(","); | |
var values = installer_arguments[key]; | |
if(values.length > 0) { | |
buf += "=" + values.join(","); | |
} | |
res.push(buf); | |
} | |
return res.join(" "); | |
} | |
describe("Player", function() { | |
var options1 = [ | |
"/installer /foo=1", | |
"/foo=2", | |
"/foo=3" | |
]; | |
var options2 = [ | |
"/installer /foo=1", | |
"/foo=2", | |
"/foo=3", | |
"/installer=foo" | |
]; | |
beforeEach(function() { | |
}); | |
it("It should parse various arguments from 1 option", function() { | |
var installer_arguments = parse_option_arguments(options1); | |
expect(installer_arguments).toEqual("/installer /foo=1,2,3"); | |
installer_arguments = parse_option_arguments(options2); | |
expect(installer_arguments).toEqual("/installer=foo /foo=1,2,3"); | |
//demonstrates use of custom matcher | |
}); | |
// describe("when song has been paused", function() { | |
// beforeEach(function() { | |
// player.play(song); | |
// player.pause(); | |
// }); | |
// | |
// it("should indicate that the song is currently paused", function() { | |
// expect(player.isPlaying).toBeFalsy(); | |
// | |
// // demonstrates use of 'not' with a custom matcher | |
// expect(player).not.toBePlaying(song); | |
// }); | |
// | |
// it("should be possible to resume", function() { | |
// player.resume(); | |
// expect(player.isPlaying).toBeTruthy(); | |
// expect(player.currentlyPlayingSong).toEqual(song); | |
// }); | |
// }); | |
// | |
// // demonstrates use of spies to intercept and test method calls | |
// it("tells the current song if the user has made it a favorite", function() { | |
// spyOn(song, 'persistFavoriteStatus'); | |
// | |
// player.play(song); | |
// player.makeFavorite(); | |
// | |
// expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true); | |
// }); | |
// | |
// //demonstrates use of expected exceptions | |
// describe("#resume", function() { | |
// it("should throw an exception if song is already playing", function() { | |
// player.play(song); | |
// | |
// expect(function() { | |
// player.resume(); | |
// }).toThrowError("song is already playing"); | |
// }); | |
// }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment