#!/usr/bin/env python

'''Unit test for our escape and unescape functions'''

# This was working fine on 2.x but not 3.x, when we were using base64

import sys

import python2x3
import escape_mod

def main():
	'''Main function'''
	all_good = True
	for string in [ 
		'/abc', 
		'/def/ghi', 
		'/jkl/mno/', 
		'abc', 
		python2x3.string_to_binary('abc'), 
		'abc\ndef\nghi', 
		'abc def ghi',
		'abc def\nghi',
		'abc%def%ghi',
		'abc%20 %%',
		]:

		encoded = escape_mod.escape(string)
		decoded = escape_mod.unescape(encoded)

		stb_string = python2x3.string_to_binary(string) 
		if stb_string == decoded:
			print('good')
		else:
			print('bad: %s, %s' % (stb_string, decoded))
			all_good = False

	if not all_good:
		sys.stderr.write('%s: One or more tests failed\n' % sys.argv[0])
		sys.exit(1)

main()