michael@0: /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const Cu = Components.utils; michael@0: Cu.import("resource://gre/modules/devtools/Loader.jsm"); michael@0: const {parseSingleValue} = devtools.require("devtools/styleinspector/css-parsing-utils"); michael@0: michael@0: const TEST_DATA = [ michael@0: {input: null, throws: true}, michael@0: {input: undefined, throws: true}, michael@0: {input: "", expected: {value: "", priority: ""}}, michael@0: {input: " \t \t \n\n ", expected: {value: "", priority: ""}}, michael@0: {input: "blue", expected: {value: "blue", priority: ""}}, michael@0: {input: "blue !important", expected: {value: "blue", priority: "important"}}, michael@0: {input: "blue!important", expected: {value: "blue", priority: "important"}}, michael@0: {input: "blue ! important", expected: {value: "blue", priority: "important"}}, michael@0: {input: "blue ! important", expected: {value: "blue", priority: "important"}}, michael@0: {input: "blue !", expected: {value: "blue", priority: ""}}, michael@0: {input: "blue !mportant", expected: {value: "blue !mportant", priority: ""}}, michael@0: {input: " blue !important ", expected: {value: "blue", priority: "important"}}, michael@0: { michael@0: input: "url(\"http://url.com/whyWouldYouDoThat!important.png\") !important", michael@0: expected: { michael@0: value: "url(\"http://url.com/whyWouldYouDoThat!important.png\")", michael@0: priority: "important" michael@0: } michael@0: }, michael@0: { michael@0: input: "url(\"http://url.com/whyWouldYouDoThat!important.png\")", michael@0: expected: { michael@0: value: "url(\"http://url.com/whyWouldYouDoThat!important.png\")", michael@0: priority: "" michael@0: } michael@0: }, michael@0: { michael@0: input: "\"content!important\" !important", michael@0: expected: { michael@0: value: "\"content!important\"", michael@0: priority: "important" michael@0: } michael@0: }, michael@0: { michael@0: input: "\"content!important\"", michael@0: expected: { michael@0: value: "\"content!important\"", michael@0: priority: "" michael@0: } michael@0: } michael@0: ]; michael@0: michael@0: function run_test() { michael@0: for (let test of TEST_DATA) { michael@0: do_print("Test input value " + test.input); michael@0: try { michael@0: let output = parseSingleValue(test.input); michael@0: assertOutput(output, test.expected); michael@0: } catch (e) { michael@0: do_print("parseSingleValue threw an exception with the given input value"); michael@0: if (test.throws) { michael@0: do_print("Exception expected"); michael@0: do_check_true(true); michael@0: } else { michael@0: do_print("Exception unexpected\n" + e); michael@0: do_check_true(false); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: function assertOutput(actual, expected) { michael@0: do_print("Check that the output has the expected value and priority"); michael@0: do_check_eq(expected.value, actual.value); michael@0: do_check_eq(expected.priority, actual.priority); michael@0: }