class ParseNodeTestCase(unittest.TestCase):
    """
    Test Node creation by parser.
    """
    def setUp(self):
        """
        Create Danlann scanner and parser for album files.
        """
        self.scanner = DanlannScanner()
        self.parser = DanlannParser()


    def parse(self, line):
        """
        Parse string with Danlann parser and return node.

        @param line: string to parse

        @see danlann.parser.Node
        """
        return self.parser.parse(self.scanner.tokenize(line))


    def testAlbum(self):
        """simple album parsing"""
        node = self.parse('/a; title; desc')
        self.assertEquals(node.type, 'album')
        self.assertEquals(node.data, ['a', 'title', 'desc'])

        node = self.parse('/adir; title')
        self.assertEquals(node.type, 'album')
        self.assertEquals(node.data, ['adir', 'title', ''])


    def testSubalbum(self):
        """simple subalbum parsing"""
        node = self.parse('/adir04')
        self.assertEquals(node.type, 'subalbum')
        self.assertEquals(node.data, ['adir04'])


    def testPhoto(self):
        """simple photo parsing"""
        node = self.parse('abc')
        self.assertEquals(node.type, 'photo')
        self.assertEquals(node.data, ['abc', '', ''])

        node = self.parse('abc; title')
        self.assertEquals(node.type, 'photo')
        self.assertEquals(node.data, ['abc', 'title', ''])

        node = self.parse('abc; title; desc')
        self.assertEquals(node.type, 'photo')
        self.assertEquals(node.data, ['abc', 'title', 'desc'])
 def setUp(self):
     """
     Create Danlann scanner instance.
     """
     self.scanner = DanlannScanner()
class ScannerTestCase(unittest.TestCase):
    """
    Test tokens created by Danlann scanner.

    @ivar scanner: Danlann scanner instance
    """
    def setUp(self):
        """
        Create Danlann scanner instance.
        """
        self.scanner = DanlannScanner()


    def tokenTypes(self, line):
        """
        Tokenize a string using Danlann scanner and return list of token
        types.

        @param line: string to parse
        """
        return [t.type for t in self.scanner.tokenize(line)]


    def tokenValues(self, line):
        """
        Tokenize a string using Danlann scanner and return list of token
        values.

        @param line: string to parse
        """
        return [t.value for t in self.scanner.tokenize(line)]


    def testComment(self):
        """comment tokens"""
        tokens = self.tokenTypes('#/a; title; desc')
        self.assertEquals(tokens, ['COMMENT'])

        values = self.tokenValues('#/a; title; desc')
        self.assertEquals(values, ['#/a; title; desc'])


    def testAlbum(self):
        """album tokens"""
        tokens = self.tokenTypes('/a; title; desc')
        self.assertEquals(tokens,
                ['SLASH', 'DIR', 'SEMICOLON', 'STRING', 'SEMICOLON', 'STRING'])

        values = self.tokenValues('/a; title; desc')
        self.assertEquals(values, ['/', 'a', ';', 'title', ';', 'desc'])

        tokens = self.tokenTypes('/a; title')
        self.assertEquals(tokens,
                ['SLASH', 'DIR', 'SEMICOLON', 'STRING'])

        values = self.tokenValues('/adir; title')
        self.assertEquals(values, ['/', 'adir', ';', 'title'])


    def testSubalbum(self):
        """subalbum tokens"""
        tokens = self.tokenTypes('/a')
        self.assertEquals(tokens, ['SLASH', 'DIR'])

        values = self.tokenValues('/adir02')
        self.assertEquals(values, ['/', 'adir02'])


    def testPhoto(self):
        """photo tokens"""
        tokens = self.tokenTypes('abc')
        self.assertEquals(tokens, ['FILE'])

        values = self.tokenValues('abc')
        self.assertEquals(values, ['abc'])

        tokens = self.tokenTypes('abc; title')
        self.assertEquals(tokens, ['FILE', 'SEMICOLON', 'STRING'])

        values = self.tokenValues('abc; title')
        self.assertEquals(values, ['abc', ';', 'title'])

        tokens = self.tokenTypes('abc; title; desc')
        self.assertEquals(tokens,
                ['FILE', 'SEMICOLON', 'STRING', 'SEMICOLON', 'STRING'])

        values = self.tokenValues('abc01; title; desc')
        self.assertEquals(values,
                ['abc01', ';', 'title', ';', 'desc'])
 def setUp(self):
     """
     Create Danlann scanner and parser for album files.
     """
     self.scanner = DanlannScanner()
     self.parser = DanlannParser()