コード例 #1
0
ファイル: blip_test.py プロジェクト: avital/thewe-1
  def testAnnotationHandling(self):
    key = 'style/fontWeight'

    def get_bold():
      for an in blip.annotations[key]:
        if an.value == 'bold':
          return an
      return None

    json = ('[{"range":{"start":3,"end":6},"name":"%s","value":"bold"}]'
            % key)
    blip = self.new_blip(blipId=ROOT_BLIP_ID,
                         annotations=simplejson.loads(json))
    self.assertEquals(1, len(blip.annotations))
    self.assertNotEqual(None, get_bold().value)
    self.assertTrue(key in blip.annotations)

    # extend the bold annotation by adding:
    blip.range(5, 8).annotate(key, 'bold')
    self.assertEquals(1, len(blip.annotations))
    self.assertEquals(8, get_bold().end)

    # clip by adding a same keyed:
    blip[4:12].annotate(key, 'italic')
    self.assertEquals(2, len(blip.annotations[key]))
    self.assertEquals(4, get_bold().end)

    # now split the italic one:
    blip.range(6, 7).clear_annotation(key)
    self.assertEquals(3, len(blip.annotations[key]))

    # clear the whole thing
    blip.all().clear_annotation(key)
    # getting to the key should now throw an exception
    self.assertRaises(KeyError, blip.annotations.__getitem__, key)
コード例 #2
0
 def testReplaceSpanAnnotation(self):
   json = ('[{"range":{"start":1,"end":4},"name":"style","value":"bold"}]')
   blip = self.new_blip(blipId=ROOT_BLIP_ID,
                        annotations=simplejson.loads(json),
                        content='\nFoo bar.')
   blip.range(2, 9).replace('')
   self.assertEqual('\nF', blip.text)
   self.assertEqual(1, blip.annotations['style'][0].start)
   self.assertEqual(2, blip.annotations['style'][0].end)
コード例 #3
0
 def testDeleteRangeThatSpansAcrossAnnotationEndPoint(self):
   json = ('[{"range":{"start":1,"end":3},"name":"style","value":"bold"}]')
   blip = self.new_blip(blipId=ROOT_BLIP_ID,
                        annotations=simplejson.loads(json),
                        content='\nFoo bar.')
   blip.range(2, 4).delete()
   self.assertEqual('\nF bar.', blip.text)
   self.assertEqual(1, blip.annotations['style'][0].start)
   self.assertEqual(2, blip.annotations['style'][0].end)
コード例 #4
0
ファイル: blip_test.py プロジェクト: JaredMiller/Wave
 def testReplaceSpanAnnotation(self):
     json = (
         '[{"range":{"start":1,"end":4},"name":"style","value":"bold"}]')
     blip = self.new_blip(blipId=ROOT_BLIP_ID,
                          annotations=simplejson.loads(json),
                          content='\nFoo bar.')
     blip.range(2, 9).replace('')
     self.assertEqual('\nF', blip.text)
     self.assertEqual(1, blip.annotations['style'][0].start)
     self.assertEqual(2, blip.annotations['style'][0].end)
コード例 #5
0
ファイル: blip_test.py プロジェクト: JaredMiller/Wave
 def testDeleteRangeThatSpansAcrossAnnotationEndPoint(self):
     json = (
         '[{"range":{"start":1,"end":3},"name":"style","value":"bold"}]')
     blip = self.new_blip(blipId=ROOT_BLIP_ID,
                          annotations=simplejson.loads(json),
                          content='\nFoo bar.')
     blip.range(2, 4).delete()
     self.assertEqual('\nF bar.', blip.text)
     self.assertEqual(1, blip.annotations['style'][0].start)
     self.assertEqual(2, blip.annotations['style'][0].end)
コード例 #6
0
  def testDocumentOperations(self):
    blip = self.new_blip(blipId=ROOT_BLIP_ID)
    newlines = [x for x in blip.find('\n')]
    self.assertEquals(2, len(newlines))
    blip.first('world').replace('jupiter')
    bits = blip.text.split('\n')
    self.assertEquals(3, len(bits))
    self.assertEquals('hello jupiter!', bits[1])
    blip.range(2, 5).delete()
    self.assertBlipStartswith('\nho jupiter', blip)

    blip.first('ho').insert_after('la')
    self.assertBlipStartswith('\nhola jupiter', blip)
    blip.at(3).insert(' ')
    self.assertBlipStartswith('\nho la jupiter', blip)
コード例 #7
0
ファイル: blip_test.py プロジェクト: JaredMiller/Wave
    def testDocumentOperations(self):
        blip = self.new_blip(blipId=ROOT_BLIP_ID)
        newlines = [x for x in blip.find('\n')]
        self.assertEquals(2, len(newlines))
        blip.first('world').replace('jupiter')
        bits = blip.text.split('\n')
        self.assertEquals(3, len(bits))
        self.assertEquals('hello jupiter!', bits[1])
        blip.range(2, 5).delete()
        self.assertBlipStartswith('\nho jupiter', blip)

        blip.first('ho').insert_after('la')
        self.assertBlipStartswith('\nhola jupiter', blip)
        blip.at(3).insert(' ')
        self.assertBlipStartswith('\nho la jupiter', blip)
コード例 #8
0
ファイル: blip_test.py プロジェクト: JaredMiller/Wave
    def testAnnotationHandling(self):
        key = 'style/fontWeight'

        def get_bold():
            for an in blip.annotations[key]:
                if an.value == 'bold':
                    return an
            return None

        json = ('[{"range":{"start":3,"end":6},"name":"%s","value":"bold"}]' %
                key)
        blip = self.new_blip(blipId=ROOT_BLIP_ID,
                             annotations=simplejson.loads(json))
        self.assertEquals(1, len(blip.annotations))
        self.assertNotEqual(None, get_bold().value)
        self.assertTrue(key in blip.annotations)

        # extend the bold annotation by adding:
        blip.range(5, 8).annotate(key, 'bold')
        self.assertEquals(1, len(blip.annotations))
        self.assertEquals(8, get_bold().end)

        # clip by adding a same keyed:
        blip[4:12].annotate(key, 'italic')
        self.assertEquals(2, len(blip.annotations[key]))
        self.assertEquals(4, get_bold().end)

        # now split the italic one:
        blip.range(6, 7).clear_annotation(key)
        self.assertEquals(3, len(blip.annotations[key]))

        # test names and iteration
        self.assertEquals(1, len(blip.annotations.names()))
        self.assertEquals(3, len([x for x in blip.annotations]))
        blip[3:5].annotate('foo', 'bar')
        self.assertEquals(2, len(blip.annotations.names()))
        self.assertEquals(4, len([x for x in blip.annotations]))
        blip[3:5].clear_annotation('foo')

        # clear the whole thing
        blip.all().clear_annotation(key)
        # getting to the key should now throw an exception
        self.assertRaises(KeyError, blip.annotations.__getitem__, key)