summary refs log blame commit diff stats
path: root/test/tc_utfwidth.py
blob: 0288c17bf5eab86e2b05896723cc4535f1e4d8d2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
32
33
34
35
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888
# -*- encoding: utf8 -*-
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# 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 3 of the License, or
# (at your option) any later version.
#
# 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

import os.path
import sys
rangerpath = os.path.join(os.path.dirname(__file__), '..')
if sys.path[1] != rangerpath:
	sys.path[1:1] = [rangerpath]
sys.path[1:1] = ['..']

from unittest import TestCase, main
from ranger.ext.utfwidth import *

a_ascii = "a"      # width = 1, bytes = 1
a_umlaut = "ä"     # width = 1, bytes = 2
a_katakana = "ア"  # width = 2, bytes = 3
# need one with width = 1 & bytes = 3

class Test(TestCase):
	def test_utf_byte_length(self):
		self.assertEqual(1, utf_byte_length(a_ascii))
		self.assertEqual(2, utf_byte_length(a_umlaut))
		self.assertEqual(3, utf_byte_length(a_katakana))

	def test_uwid(self):
		self.assertEqual(1, uwid(a_ascii))
		self.assertEqual(1, uwid(a_umlaut))
		self.assertEqual(2, uwid(a_katakana))
		self.assertEqual(3, uwid(a_katakana + a_umlaut))
		self.assertEqual(4, uwid("asdf"))
		self.assertEqual(5, uwid("löööl"))
		self.assertEqual(6, uwid("バババ"))

if __name__ == '__main__': main()
class="n">end(); trace("test layer 2") << "bar" << end(); trace("test layer 1") << "qux" << end(); CHECK_TRACE_CONTENTS("test layer 1: foo\n" "test layer 2: bar\n" "test layer 1: qux\n"); } void test_trace_supports_count() { trace("test layer 1") << "foo" << end(); trace("test layer 1") << "foo" << end(); CHECK_EQ(trace_count("test layer 1", "foo"), 2); } void test_trace_supports_count2() { trace("test layer 1") << "foo" << end(); trace("test layer 1") << "bar" << end(); CHECK_EQ(trace_count("test layer 1"), 2); } void test_trace_count_ignores_trailing_whitespace() { trace("test layer 1") << "foo\n" << end(); CHECK_EQ(trace_count("test layer 1", "foo"), 1); } void test_trace_unescapes_newlines() { trace("test layer 1") << "f\no\no\n" << end(); CHECK_TRACE_CONTENTS("test layer 1: f\\no\\no"); } // pending: DUMP tests // pending: readable_contents() adds newline if necessary. // pending: raise also prints to stderr. // pending: raise doesn't print to stderr if Hide_errors is set. // pending: warn doesn't print to stderr if Hide_errors is set. // pending: warn doesn't print to stderr if Hide_warnings is set. // pending: raise doesn't have to be saved if Hide_errors is set, just printed. // pending: raise prints to stderr if Trace_stream is NULL. // pending: raise prints to stderr if Trace_stream is NULL even if Hide_errors is set. // can't check trace because trace methods call 'split' void test_split_returns_at_least_one_elem() { vector<string> result = split("", ","); CHECK_EQ(result.size(), 1); CHECK_EQ(result.at(0), ""); } void test_split_returns_entire_input_when_no_delim() { vector<string> result = split("abc", ","); CHECK_EQ(result.size(), 1); CHECK_EQ(result.at(0), "abc"); } void test_split_works() { vector<string> result = split("abc,def", ","); CHECK_EQ(result.size(), 2); CHECK_EQ(result.at(0), "abc"); CHECK_EQ(result.at(1), "def"); } void test_split_works2() { vector<string> result = split("abc,def,ghi", ","); CHECK_EQ(result.size(), 3); CHECK_EQ(result.at(0), "abc"); CHECK_EQ(result.at(1), "def"); CHECK_EQ(result.at(2), "ghi"); } void test_split_handles_multichar_delim() { vector<string> result = split("abc,,def,,ghi", ",,"); CHECK_EQ(result.size(), 3); CHECK_EQ(result.at(0), "abc"); CHECK_EQ(result.at(1), "def"); CHECK_EQ(result.at(2), "ghi"); } void test_trim() { CHECK_EQ(trim(""), ""); CHECK_EQ(trim(" "), ""); CHECK_EQ(trim(" "), ""); CHECK_EQ(trim("a"), "a"); CHECK_EQ(trim(" a"), "a"); CHECK_EQ(trim(" a"), "a"); CHECK_EQ(trim(" ab"), "ab"); CHECK_EQ(trim("a "), "a"); CHECK_EQ(trim("a "), "a"); CHECK_EQ(trim("ab "), "ab"); CHECK_EQ(trim(" a "), "a"); CHECK_EQ(trim(" a "), "a"); CHECK_EQ(trim(" ab "), "ab"); }