2023-01-07 20:26:17 +01:00
|
|
|
var _utils = load('res://addons/gut/utils.gd').get_instance()
|
2022-06-02 04:13:43 +02:00
|
|
|
var _strutils = _utils.Strutils.new()
|
2023-01-07 20:26:17 +01:00
|
|
|
const INDENT = ' '
|
2022-06-02 04:13:43 +02:00
|
|
|
var _max_to_display = 30
|
|
|
|
const ABSOLUTE_MAX_DISPLAYED = 10000
|
|
|
|
const UNLIMITED = -1
|
|
|
|
|
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
func _single_diff(diff, depth=0):
|
2022-06-02 04:13:43 +02:00
|
|
|
var to_return = ""
|
|
|
|
var brackets = diff.get_brackets()
|
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
if(brackets != null and !diff.are_equal):
|
|
|
|
to_return = ''
|
|
|
|
to_return += str(brackets.open, "\n",
|
|
|
|
_strutils.indent_text(differences_to_s(diff.differences, depth), depth+1, INDENT), "\n",
|
|
|
|
brackets.close)
|
2022-06-02 04:13:43 +02:00
|
|
|
else:
|
|
|
|
to_return = str(diff)
|
|
|
|
|
|
|
|
return to_return
|
|
|
|
|
|
|
|
|
|
|
|
func make_it(diff):
|
2023-01-07 20:26:17 +01:00
|
|
|
var to_return = ''
|
|
|
|
if(diff.are_equal):
|
2022-06-02 04:13:43 +02:00
|
|
|
to_return = diff.summary
|
|
|
|
else:
|
2023-01-07 20:26:17 +01:00
|
|
|
if(_max_to_display == ABSOLUTE_MAX_DISPLAYED):
|
|
|
|
to_return = str(diff.get_value_1(), ' != ', diff.get_value_2())
|
2022-06-02 04:13:43 +02:00
|
|
|
else:
|
|
|
|
to_return = diff.get_short_summary()
|
2023-01-07 20:26:17 +01:00
|
|
|
to_return += str("\n", _strutils.indent_text(_single_diff(diff, 0), 1, ' '))
|
2022-06-02 04:13:43 +02:00
|
|
|
return to_return
|
|
|
|
|
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
func differences_to_s(differences, depth=0):
|
|
|
|
var to_return = ''
|
2022-06-02 04:13:43 +02:00
|
|
|
var keys = differences.keys()
|
|
|
|
keys.sort()
|
|
|
|
var limit = min(_max_to_display, differences.size())
|
|
|
|
|
|
|
|
for i in range(limit):
|
|
|
|
var key = keys[i]
|
|
|
|
to_return += str(key, ": ", _single_diff(differences[key], depth))
|
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
if(i != limit -1):
|
2022-06-02 04:13:43 +02:00
|
|
|
to_return += "\n"
|
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
if(differences.size() > _max_to_display):
|
2022-06-02 04:13:43 +02:00
|
|
|
to_return += str("\n\n... ", differences.size() - _max_to_display, " more.")
|
|
|
|
|
|
|
|
return to_return
|
|
|
|
|
|
|
|
|
|
|
|
func get_max_to_display():
|
|
|
|
return _max_to_display
|
|
|
|
|
|
|
|
|
|
|
|
func set_max_to_display(max_to_display):
|
|
|
|
_max_to_display = max_to_display
|
2023-01-07 20:26:17 +01:00
|
|
|
if(_max_to_display == UNLIMITED):
|
2022-06-02 04:13:43 +02:00
|
|
|
_max_to_display = ABSOLUTE_MAX_DISPLAYED
|
2023-01-07 20:26:17 +01:00
|
|
|
|