<filename>tests/test_mapping.py<gh_stars>1-10
import unittest

from construct import Flag

class TestFlag(unittest.TestCase):

    def test_parse(self):
        flag = Flag("flag")
        self.assertTrue(flag.parse(b"\x01"))

    def test_parse_flipped(self):
        flag = Flag("flag", truth=0, falsehood=1)
        self.assertFalse(flag.parse(b"\x01"))

    def test_parse_default(self):
        flag = Flag("flag")
        self.assertFalse(flag.parse(b"\x02"))

    def test_parse_default_true(self):
        flag = Flag("flag", default=True)
        self.assertTrue(flag.parse(b"\x02"))

    def test_build(self):
        flag = Flag("flag")
        self.assertEqual(flag.build(True), b"\x01")

    def test_build_flipped(self):
        flag = Flag("flag", truth=0, falsehood=1)
        self.assertEqual(flag.build(True), b"\x00")

