[diffoscope] 01/01: Add test for js-beautify (JS comparator)
Emanuel Bronshtein
e3amn2l-guest at moszumanska.debian.org
Wed Dec 21 02:27:35 UTC 2016
This is an automated email from the git hooks/post-receive script.
e3amn2l-guest pushed a commit to branch master
in repository diffoscope.
commit 9bbcf2f6ce5dc711a9dc07c731cddcc5db9fa681
Author: Emanuel Bronshtein <e3amn2l at gmx.com>
Date: Wed Dec 21 04:27:31 2016 +0200
Add test for js-beautify (JS comparator)
---
tests/comparators/test_javascript.py | 52 ++++++++++++++++++++++++++++++++++++
tests/data/javascript_expected_diff | 13 +++++++++
tests/data/test1.js | 1 +
tests/data/test2.js | 1 +
4 files changed, 67 insertions(+)
diff --git a/tests/comparators/test_javascript.py b/tests/comparators/test_javascript.py
new file mode 100644
index 0000000..4fb3a31
--- /dev/null
+++ b/tests/comparators/test_javascript.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2016 Emanuel Bronshtein <e3amn2l at gmx.com>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
+
+import pytest
+
+from diffoscope.config import Config
+from diffoscope.comparators.javascript import JavaScriptFile
+from diffoscope.comparators.binary import NonExistingFile
+
+from utils import skip_unless_tools_exist, data, load_fixture
+
+javascript1 = load_fixture(data('test1.js'))
+javascript2 = load_fixture(data('test2.js'))
+
+def test_identification(javascript1):
+ assert isinstance(javascript1, JavaScriptFile)
+
+def test_no_differences(javascript1):
+ difference = javascript1.compare(javascript1)
+ assert difference is None
+
+ at pytest.fixture
+def differences(javascript1, javascript2):
+ return javascript1.compare(javascript2).details
+
+ at skip_unless_tools_exist('js-beautify')
+def test_diff(differences):
+ expected_diff = open(data('javascript_expected_diff')).read()
+ assert differences[0].unified_diff == expected_diff
+
+ at skip_unless_tools_exist('js-beautify')
+def test_compare_non_existing(monkeypatch, javascript1):
+ monkeypatch.setattr(Config(), 'new_file', True)
+ difference = javascript1.compare(NonExistingFile('/nonexisting', javascript1))
+ assert difference.source2 == '/nonexisting'
+ assert len(difference.details) > 0
diff --git a/tests/data/javascript_expected_diff b/tests/data/javascript_expected_diff
new file mode 100644
index 0000000..db661c2
--- /dev/null
+++ b/tests/data/javascript_expected_diff
@@ -0,0 +1,13 @@
+@@ -1,8 +1,8 @@
+ function test(str) {
+ alert(str);
+- prompt(str, "TEST1")
++ prompt(str, "TEST2")
+ }
+ x = 1;
+-y = 2;
+-z = /.+/;
+-d = [2015, 2016]; //comment
++y = 3;
++z = /.*/;
++d = [2015, 2016, 2017]; //comment
diff --git a/tests/data/test1.js b/tests/data/test1.js
new file mode 100644
index 0000000..df588ba
--- /dev/null
+++ b/tests/data/test1.js
@@ -0,0 +1 @@
+function test(str) { alert(str);prompt(str,"TEST1")}x=1;y=2;z=/.+/;d=[2015,2016]; //comment
diff --git a/tests/data/test2.js b/tests/data/test2.js
new file mode 100644
index 0000000..744d4dd
--- /dev/null
+++ b/tests/data/test2.js
@@ -0,0 +1 @@
+function test(str) { alert(str);prompt(str,"TEST2")}x=1;y=3;z=/.*/;d=[2015,2016,2017]; //comment
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list