summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2015-07-10 09:43:53 +0100
committerJose Fonseca <jfonseca@vmware.com>2015-07-10 09:43:53 +0100
commitdcdeba4e6142030b3dc0daf8261bb5f0a764a140 (patch)
tree05b34d1b824cab55531893ecbdf8e6d7977ffe9b /scripts
parenta01a4b5ad7dfddd26deb1b93d9dffc684ba52ba7 (diff)
jsondiff: Better formating of shader differences.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/jsondiff.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/scripts/jsondiff.py b/scripts/jsondiff.py
index a76d0c9d..3b1f9110 100755
--- a/scripts/jsondiff.py
+++ b/scripts/jsondiff.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
##########################################################################
#
+# Copyright 2015 VMware, Inc.
# Copyright 2011 Jose Fonseca
# All Rights Reserved.
#
@@ -28,6 +29,7 @@
import json
import optparse
import re
+import difflib
import sys
@@ -131,7 +133,7 @@ class Dumper(Visitor):
self._write(']')
def visitValue(self, node):
- self._write(json.dumps(node))
+ self._write(json.dumps(node, allow_nan=True))
@@ -252,10 +254,38 @@ class Differ(Visitor):
self.replace(a, b)
def replace(self, a, b):
+ if self.isMultilineString(a) or self.isMultilineString(b):
+ a = str(a)
+ b = str(b)
+ a = a.splitlines()
+ b = b.splitlines()
+ differ = difflib.Differ()
+ result = differ.compare(a, b)
+ self.dumper.level += 1
+ for entry in result:
+ self.dumper._newline()
+ self.dumper._indent()
+ tag = entry[:2]
+ text = entry[2:]
+ if tag == '? ':
+ tag = ' '
+ prefix = ' '
+ text = text.rstrip()
+ suffix = ''
+ else:
+ prefix = '"'
+ suffix = '\\n"'
+ line = tag + prefix + text + suffix
+ self.dumper._write(line)
+ self.dumper.level -= 1
+ return
self.dumper.visit(a)
self.dumper._write(' -> ')
self.dumper.visit(b)
+ def isMultilineString(self, value):
+ return isinstance(value, basestring) and '\n' in value
+
#
# Unfortunately JSON standard does not include comments, but this is a quite