config/tests/unit-LineEndings.py
author Matthew Noorenberghe <mozilla@noorenberghe.ca>
Fri, 12 Jul 2013 19:16:12 -0700
branchCOMM2000_20110114_RELBRANCH
changeset 140223 25093037bf154fcf729972d04b5bd7252fef4fd6
parent 15217 4157b3484b8ecb5908c479b3523359a1c846f63b
child 100388 2d56621abfee7ceee3ca85cfc74c1c12b65c643c
permissions -rw-r--r--
Bug 845692 - Close version 2.0 release branches. a=bhearsum

import unittest

from StringIO import StringIO
import os
import sys
import os.path
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from Preprocessor import Preprocessor

class TestLineEndings(unittest.TestCase):
  """
  Unit tests for the Context class
  """

  def setUp(self):
    self.pp = Preprocessor()
    self.pp.out = StringIO()
    self.tempnam = os.tempnam('.')

  def tearDown(self):
    os.remove(self.tempnam)

  def createFile(self, lineendings):
    f = open(self.tempnam, 'wb')
    for line, ending in zip(['a', '#literal b', 'c'], lineendings):
      f.write(line+ending)
    f.close()

  def testMac(self):
    self.createFile(['\x0D']*3)
    self.pp.do_include(self.tempnam)
    self.assertEquals(self.pp.out.getvalue(), 'a\nb\nc\n')

  def testUnix(self):
    self.createFile(['\x0A']*3)
    self.pp.do_include(self.tempnam)
    self.assertEquals(self.pp.out.getvalue(), 'a\nb\nc\n')

  def testWindows(self):
    self.createFile(['\x0D\x0A']*3)
    self.pp.do_include(self.tempnam)
    self.assertEquals(self.pp.out.getvalue(), 'a\nb\nc\n')

if __name__ == '__main__':
  unittest.main()