# Regina - A Normal Surface Theory Calculator
# Python Test Suite Component
#
# Copyright (c) 2007-2021, Ben Burton
# For further details contact Ben Burton (bab@debian.org).
#
# Tests for UTF-8 character encodings when loading and importing files
#
# This file is a single component of Regina's python test suite.  To run
# the python test suite, move to the main python directory in the source
# tree and run "make check".
#
# This program 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 2 of the
# License, or (at your option) any later version.
#
# As an exception, when this program is distributed through (i) the
# App Store by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or
# (iii) Google Play by Google Inc., then that store may impose any
# digital rights management, device limits and/or redistribution
# restrictions that are required by its terms of service.
#
# This program 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 this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.

# Fetch the python/testsuite path in the source tree, since we will need
# to access external files.
import sys
if (len(sys.argv) > 1):
	testpath = sys.argv[1]
else:
	testpath = '.'

# Make sure we get the transition between LATIN1 and UTF-8 regimes correct.
oldVersions = [ '0', '01', '1', '2', '3', '4',
	'0.0', '0.1', '0.4', '0.5', '0.9', '0.10',
	'1.0', '1.1', '1.4', '1.5', '1.9', '1.10',
	'2.0', '2.1', '2.4', '2.5', '2.9', '2.10',
	'3.0', '3.1', '3.4', '3.5', '3.9', '3.10',
	'4.0', '4.01', '4.1', '4.2', '4.3', '4.4', '4.4.1', '4.4.9' ]
newVersions = [ '', '5', '6', '7', '8', '9', '10', '20', '30', '40', '50', '90',
	'4.5', '4.6', '4.9', '4.10', '4.20', '4.30', '4.40', '4.50', '4.90',
	'5.0', '5.1', '5.4', '5.5', '5.9', '9.1', '9.9', '10.1', '10.9',
	'40.1', '40.9', '50.1', '50.9' ]
suffixes = [ '', 'a', 'alpha', '.', '.0', '.01', '.0.1', '.1',
	'+a', '-a', '-0', '-1', '-9', '-10' ]

for v in oldVersions:
	for s in suffixes:
		if regina.versionUsesUTF8(v + s):
			print('ERROR: Version ' + v + s + ' claims to use UTF-8.')

for v in newVersions:
	for s in suffixes:
		if not regina.versionUsesUTF8(v + s):
			print('ERROR: Version ' + v + s + ' does not claim to use UTF-8.')

# Load a file created by an old version of regina.  This file stores it
# strings as LATIN1, which should be converted to UTF-8 on import.
i18nOld = regina.open(testpath + '/i18n-latin1.rga')
if i18nOld != None:
	print(i18nOld.label())
	print(i18nOld.text())

# Load a version of the same file created by a newer version of Regina,
# which stores strings directly in UTF-8.
i18nNew = regina.open(testpath + '/i18n-utf8.rga')
if i18nNew != None:
	print(i18nNew.label())
	print(i18nNew.text())

# Import a triangulation from SnapPea that uses a subscript character in
# the triangulation name.
subscriptImport = SnapPeaTriangulation(testpath + '/O2_1.tri')
if subscriptImport != None:
	print(subscriptImport.label())

# Load a Regina data file with a pre-saved version of this same SnapPea
# triangulation.
subscriptLoad = regina.open(testpath + '/O2_1.rga')
if subscriptLoad != None:
	print(subscriptLoad.firstChild().label())

