"""
Convert languages and language codes into ISO names

Copyright (c) 2014 Mikael Karlsson (CSC - IT Center for Science Ltd.).
Licensed under AGPLv3.
"""

from iso_639_3 import iso_639_3, languages
from examples.logic import map_language

class LogicFunctionality(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.english = languages.get(name='English')
        cls.chinese = languages.get(name='Chinese')
        cls.arabic = languages.get(name='Arabic')
        cls.moroccan = languages.get(name='Moroccan Arabic')
        cls.tzeltal = languages.get(name='Tzeltal')

    def test_logic_2_char_code(self):
        self.assertIs(map_language('En'), self.english)
        self.assertIs(map_language('EN'), self.english)
        self.assertIs(map_language('eN'), self.english)
        self.assertIs(map_language('en'), self.english)

    def test_logic_3_char_code(self):
        self.assertIs(map_language('Eng'), self.english)
        self.assertIs(map_language('eNg'), self.english)
        self.assertIs(map_language('enG'), self.english)
        self.assertIs(map_language('ENG'), self.english)
        self.assertIs(map_language('eng'), self.english)
        self.assertIs(map_language('zho'), self.chinese)
        self.assertIs(map_language('chi'), self.chinese)
        self.assertIs(map_language('ara'), self.arabic)

    def test_logic_name(self):
        self.assertIs(map_language('english'), self.english)
        self.assertIs(map_language('English'), self.english)
        self.assertIs(map_language('eNgLiSh'), self.english)
        self.assertIs(map_language('ENGLISH'), self.english)
        self.assertIs(map_language('Arabic, Moroccan'), self.moroccan)
        self.assertIs(map_language('Arabic, Moroccan Spoken'), self.arabic)

    def test_logic_locale(self):
        self.assertIs(map_language('En_Us'), self.english)
        self.assertIs(map_language('EN_US'), self.english)
        self.assertIs(map_language('en_us'), self.english)


if dash3:
    assert(map_language('ary') is moroccan)
    assert(languages.alpha3['ary'] is moroccan)
    assert(languages.get(alpha3='ary') is moroccan)
    assert(map_language('Moroccan Arabic') is moroccan)
    assert(map_language('Tzeltal') is tzeltal)
    assert(map_language('tzh') is tzeltal)
else:
    assert(map_language('Moroccan Arabic') is arabic)

@@ -1983,29 +1983,61 @@
 h)%0A%0A
-%0Aif dash3:%0A    
+    def test_logic_dash3(self):%0A        self.
 assert
+Is
 (map
@@ -2048,28 +2048,31 @@
 guage('ary')
- is 
+, self.
 moroccan)%0A  
@@ -2065,38 +2065,49 @@
 f.moroccan)%0A    
+    self.
 assert
+Is
 (languages.alpha
@@ -2114,20 +2114,23 @@
 3%5B'ary'%5D
- is 
+, self.
 moroccan
@@ -2135,22 +2135,33 @@
 an)%0A    
+    self.
 assert
+Is
 (languag
@@ -2180,20 +2180,23 @@
 3='ary')
- is 
+, self.
 moroccan
@@ -2193,38 +2193,49 @@
 f.moroccan)%0A    
+    self.
 assert
+Is
 (map_language('M
@@ -2250,20 +2250,23 @@
 Arabic')
- is 
+, self.
 moroccan
@@ -2267,30 +2267,41 @@
 roccan)%0A    
+  
+  self.
 assert
+Is
 (map_languag
@@ -2312,20 +2312,94 @@
 zeltal')
- is 
+, self.tzeltal)%0A        self.assertIs(map_language('Tzeltal, Tenejapa'), self.
 tzeltal)
@@ -2399,30 +2399,41 @@
 zeltal)%0A    
+    self.
 assert
+Is
 (map_languag
@@ -2440,20 +2440,23 @@
 e('tzh')
- is 
+, self.
 tzeltal)
@@ -2460,24 +2460,65 @@
 al)%0A
-else
+%0A    def test_logic_dash2(self)
 :%0A    
+ 
+   self.
 assert
+Equal
 (map
@@ -2548,17 +2548,30 @@
 bic'
-) is a
+, False).name, 'A
 rabic
+'
 )%0A
+%0A

Create test for dash2 and dash3