def testGetLink(self): test_data = json.loads(self._ReadLocalFile('fake_data_source.json')) resolver = ReferenceResolver(_FakeAPIDataSource(test_data), _FakeAPIModels(test_data.keys()), TestObjectStore('test')) self.assertEqual({ 'href': 'foo', 'text': 'foo', 'name': 'foo' }, resolver.GetLink('foo', namespace='baz')) self.assertEqual({ 'href': 'foo#type-foo_t1', 'text': 'foo.foo_t1', 'name': 'foo_t1' }, resolver.GetLink('foo.foo_t1', namespace='baz')) self.assertEqual({ 'href': 'baz#event-baz_e1', 'text': 'baz_e1', 'name': 'baz_e1' }, resolver.GetLink('baz.baz_e1', namespace='baz')) self.assertEqual({ 'href': 'baz#event-baz_e1', 'text': 'baz_e1', 'name': 'baz_e1' }, resolver.GetLink('baz_e1', namespace='baz')) self.assertEqual({ 'href': 'foo#method-foo_f1', 'text': 'foo.foo_f1', 'name': 'foo_f1' }, resolver.GetLink('foo.foo_f1', namespace='baz')) self.assertEqual({ 'href': 'foo#property-foo_p3', 'text': 'foo.foo_p3', 'name': 'foo_p3' }, resolver.GetLink('foo.foo_p3', namespace='baz')) self.assertEqual({ 'href': 'bar.bon#type-bar_bon_t3', 'text': 'bar.bon.bar_bon_t3', 'name': 'bar_bon_t3' }, resolver.GetLink('bar.bon.bar_bon_t3', namespace='baz')) self.assertEqual({ 'href': 'bar.bon#property-bar_bon_p3', 'text': 'bar_bon_p3', 'name': 'bar_bon_p3' }, resolver.GetLink('bar_bon_p3', namespace='bar.bon')) self.assertEqual({ 'href': 'bar.bon#property-bar_bon_p3', 'text': 'bar_bon_p3', 'name': 'bar_bon_p3' }, resolver.GetLink('bar.bon.bar_bon_p3', namespace='bar.bon')) self.assertEqual({ 'href': 'bar#event-bar_e2', 'text': 'bar_e2', 'name': 'bar_e2' }, resolver.GetLink('bar.bar_e2', namespace='bar')) self.assertEqual({ 'href': 'bar#type-bon', 'text': 'bon', 'name': 'bon' }, resolver.GetLink('bar.bon', namespace='bar')) self.assertEqual({ 'href': 'foo#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, resolver.GetLink('foo_t3.foo_t3_e1', namespace='foo')) self.assertEqual({ 'href': 'foo#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, resolver.GetLink('foo.foo_t3.foo_t3_e1', namespace='foo')) self.assertEqual({ 'href': 'foo#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, resolver.GetLink('foo.foo_p1.foo_t3_e1', namespace='foo')) self.assertEqual({ 'href': 'bar#property-bar_t1-bar_t1_p1', 'text': 'bar.bar_t1.bar_t1_p1', 'name': 'bar_t1_p1' }, resolver.GetLink('bar.bar_p3.bar_t1_p1', namespace='foo')) self.assertEqual({ 'href': 'bar#property-bar_t1-bar_t1_p1', 'text': 'bar_t1.bar_t1_p1', 'name': 'bar_t1_p1' }, resolver.GetLink('bar_p3.bar_t1_p1', namespace='bar')) self.assertEqual( None, resolver.GetLink('bar.bar_p3.bar_t2_p1', namespace='bar')) self.assertEqual( None, resolver.GetLink('bar.bon.bar_e3', namespace='bar')) self.assertEqual( None, resolver.GetLink('bar_p3', namespace='baz.bon')) self.assertEqual( None, resolver.GetLink('falafel.faf', namespace='a')) self.assertEqual( None, resolver.GetLink('bar_p3', namespace='foo')) self.assertEqual( 'Hello <a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>, ' '<a href="bar.bon#property-bar_bon_p3">Bon Bon</a>, ' '<a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>', resolver.ResolveAllLinks( 'Hello $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', namespace='bar.bon')) self.assertEqual( 'I like <a href="bar#property-bar_t1-bar_t1_p1">food</a>.', resolver.ResolveAllLinks('I like $ref:[bar.bar_p3.bar_t1_p1 food].', namespace='foo')) self.assertEqual( 'Ref <a href="foo">It\'s foo!</a>', resolver.ResolveAllLinks('Ref $ref:[foo It\'s foo!]', namespace='bar')) self.assertEqual( 'Ref <a href="bar#type-bon">Bon</a>', resolver.ResolveAllLinks('Ref $ref:[bar.bon Bon]', namespace='bar')) # Different kinds of whitespace can be significant inside <pre> tags. self.assertEqual( '<pre><a href="bar#type-bon">bar.bon</a>({\nkey: value})', resolver.ResolveAllLinks('<pre>$ref:[bar.bon]({\nkey: value})', namespace='baz')) # Allow bare "$ref:foo.bar." at the end of a string. self.assertEqual( '<a href="bar#type-bon">bar.bon</a>.', resolver.ResolveAllLinks('$ref:bar.bon.', namespace='baz')) # If a request is provided it should construct an appropriate relative link. self.assertEqual( 'Hi <a href="../../bar.bon#property-bar_bon_p3">bar_bon_p3</a>, ' '<a href="../../bar.bon#property-bar_bon_p3">Bon Bon</a>, ' '<a href="../../bar.bon#property-bar_bon_p3">bar_bon_p3</a>', resolver.ResolveAllLinks( 'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', relative_to='big/long/path/bar.html', namespace='bar.bon')) self.assertEqual( 'Hi <a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>, ' '<a href="bar.bon#property-bar_bon_p3">Bon Bon</a>, ' '<a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>', resolver.ResolveAllLinks( 'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', relative_to='', namespace='bar.bon')) self.assertEqual( 'Hi <a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>, ' '<a href="bar.bon#property-bar_bon_p3">Bon Bon</a>, ' '<a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>', resolver.ResolveAllLinks( 'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', relative_to='bar.html', namespace='bar.bon')) self.assertEqual( 'Hi <a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>, ' '<a href="bar.bon#property-bar_bon_p3">Bon Bon</a>, ' '<a href="bar.bon#property-bar_bon_p3">bar_bon_p3</a>', resolver.ResolveAllLinks( 'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', relative_to='foo/bar.html', namespace='bar.bon')) self.assertEqual( 'Hi <a href="../bar.bon#property-bar_bon_p3">bar_bon_p3</a>, ' '<a href="../bar.bon#property-bar_bon_p3">Bon Bon</a>, ' '<a href="../bar.bon#property-bar_bon_p3">bar_bon_p3</a>', resolver.ResolveAllLinks( 'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', relative_to='foo/baz/bar.html', namespace='bar.bon'))
def testGetLink(self): data_source = FakeAPIDataSource( json.loads(self._ReadLocalFile('fake_data_source.json'))) resolver = ReferenceResolver(data_source, data_source, TestObjectStore('test')) self.assertEqual({ 'href': 'foo.html', 'text': 'foo', 'name': 'foo' }, resolver.GetLink('foo', namespace='baz')) self.assertEqual( { 'href': 'foo.html#type-foo_t1', 'text': 'foo.foo_t1', 'name': 'foo_t1' }, resolver.GetLink('foo.foo_t1', namespace='baz')) self.assertEqual( { 'href': 'baz.html#event-baz_e1', 'text': 'baz_e1', 'name': 'baz_e1' }, resolver.GetLink('baz.baz_e1', namespace='baz')) self.assertEqual( { 'href': 'baz.html#event-baz_e1', 'text': 'baz_e1', 'name': 'baz_e1' }, resolver.GetLink('baz_e1', namespace='baz')) self.assertEqual( { 'href': 'foo.html#method-foo_f1', 'text': 'foo.foo_f1', 'name': 'foo_f1' }, resolver.GetLink('foo.foo_f1', namespace='baz')) self.assertEqual( { 'href': 'foo.html#property-foo_p3', 'text': 'foo.foo_p3', 'name': 'foo_p3' }, resolver.GetLink('foo.foo_p3', namespace='baz')) self.assertEqual( { 'href': 'bar.bon.html#type-bar_bon_t3', 'text': 'bar.bon.bar_bon_t3', 'name': 'bar_bon_t3' }, resolver.GetLink('bar.bon.bar_bon_t3', namespace='baz')) self.assertEqual( { 'href': 'bar.bon.html#property-bar_bon_p3', 'text': 'bar_bon_p3', 'name': 'bar_bon_p3' }, resolver.GetLink('bar_bon_p3', namespace='bar.bon')) self.assertEqual( { 'href': 'bar.bon.html#property-bar_bon_p3', 'text': 'bar_bon_p3', 'name': 'bar_bon_p3' }, resolver.GetLink('bar.bon.bar_bon_p3', namespace='bar.bon')) self.assertEqual( { 'href': 'bar.html#event-bar_e2', 'text': 'bar_e2', 'name': 'bar_e2' }, resolver.GetLink('bar.bar_e2', namespace='bar')) self.assertEqual( { 'href': 'bar.html#type-bon', 'text': 'bon', 'name': 'bon' }, resolver.GetLink('bar.bon', namespace='bar')) self.assertEqual( { 'href': 'foo.html#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, resolver.GetLink('foo_t3.foo_t3_e1', namespace='foo')) self.assertEqual( { 'href': 'foo.html#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, resolver.GetLink('foo.foo_t3.foo_t3_e1', namespace='foo')) self.assertEqual( { 'href': 'foo.html#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, resolver.GetLink('foo.foo_p1.foo_t3_e1', namespace='foo')) self.assertEqual( { 'href': 'bar.html#property-bar_t1-bar_t1_p1', 'text': 'bar.bar_t1.bar_t1_p1', 'name': 'bar_t1_p1' }, resolver.GetLink('bar.bar_p3.bar_t1_p1', namespace='foo')) self.assertEqual( { 'href': 'bar.html#property-bar_t1-bar_t1_p1', 'text': 'bar_t1.bar_t1_p1', 'name': 'bar_t1_p1' }, resolver.GetLink('bar_p3.bar_t1_p1', namespace='bar')) self.assertEqual( None, resolver.GetLink('bar.bar_p3.bar_t2_p1', namespace='bar')) self.assertEqual(None, resolver.GetLink('bar.bon.bar_e3', namespace='bar')) self.assertEqual(None, resolver.GetLink('bar_p3', namespace='baz.bon')) self.assertEqual(None, resolver.GetLink('falafel.faf', namespace='a')) self.assertEqual(None, resolver.GetLink('bar_p3', namespace='foo')) self.assertEqual( 'Hello <a href="bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>, ' '<a href="bar.bon.html#property-bar_bon_p3">Bon Bon</a>, ' '<a href="bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>', resolver.ResolveAllLinks( 'Hello $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', namespace='bar.bon')) self.assertEqual( 'I like <a href="bar.html#property-bar_t1-bar_t1_p1">food</a>.', resolver.ResolveAllLinks( 'I like $ref:[bar.bar_p3.bar_t1_p1 food].', namespace='foo')) self.assertEqual( 'Ref <a href="foo.html">It\'s foo!</a>', resolver.ResolveAllLinks('Ref $ref:[foo It\'s foo!]', namespace='bar')) self.assertEqual( 'Ref <a href="bar.html#type-bon">Bon</a>', resolver.ResolveAllLinks('Ref $ref:[bar.bon Bon]', namespace='bar')) # Different kinds of whitespace can be significant inside <pre> tags. self.assertEqual( '<pre><a href="bar.html#type-bon">bar.bon</a>({\nkey: value})', resolver.ResolveAllLinks('<pre>$ref:[bar.bon]({\nkey: value})', namespace='baz')) # Allow bare "$ref:foo.bar." at the end of a string. self.assertEqual( '<a href="bar.html#type-bon">bar.bon</a>.', resolver.ResolveAllLinks('$ref:bar.bon.', namespace='baz'))
def testGetLink(self): data_source = FakeAPIDataSource( json.loads(self._ReadLocalFile('fake_data_source.json'))) resolver = ReferenceResolver(data_source, data_source, InMemoryObjectStore('')) self.assertEqual( { 'href': 'foo.html#type-foo_t1', 'text': 'foo.foo_t1', 'name': 'foo_t1' }, resolver.GetLink('foo.foo_t1', 'baz')) self.assertEqual( { 'href': 'baz.html#event-baz_e1', 'text': 'baz_e1', 'name': 'baz_e1' }, resolver.GetLink('baz.baz_e1', 'baz')) self.assertEqual( { 'href': 'baz.html#event-baz_e1', 'text': 'baz_e1', 'name': 'baz_e1' }, resolver.GetLink('baz_e1', 'baz')) self.assertEqual( { 'href': 'foo.html#method-foo_f1', 'text': 'foo.foo_f1', 'name': 'foo_f1' }, resolver.GetLink('foo.foo_f1', 'baz')) self.assertEqual( { 'href': 'foo.html#property-foo_p3', 'text': 'foo.foo_p3', 'name': 'foo_p3' }, resolver.GetLink('foo.foo_p3', 'baz')) self.assertEqual( { 'href': 'bar.bon.html#type-bar_bon_t3', 'text': 'bar.bon.bar_bon_t3', 'name': 'bar_bon_t3' }, resolver.GetLink('bar.bon.bar_bon_t3', 'baz')) self.assertEqual( { 'href': 'bar.bon.html#property-bar_bon_p3', 'text': 'bar_bon_p3', 'name': 'bar_bon_p3' }, resolver.GetLink('bar_bon_p3', 'bar.bon')) self.assertEqual( { 'href': 'bar.bon.html#property-bar_bon_p3', 'text': 'bar_bon_p3', 'name': 'bar_bon_p3' }, resolver.GetLink('bar.bon.bar_bon_p3', 'bar.bon')) self.assertEqual( { 'href': 'bar.html#event-bar_e2', 'text': 'bar_e2', 'name': 'bar_e2' }, resolver.GetLink('bar.bar_e2', 'bar')) self.assertEqual( { 'href': 'bar.html#type-bon', 'text': 'bon', 'name': 'bon' }, resolver.GetLink('bar.bon', 'bar')) self.assertEqual( { 'href': 'foo.html#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, resolver.GetLink('foo_t3.foo_t3_e1', 'foo')) self.assertEqual( { 'href': 'foo.html#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, resolver.GetLink('foo.foo_t3.foo_t3_e1', 'foo')) self.assertEqual( { 'href': 'foo.html#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, resolver.GetLink('foo.foo_p1.foo_t3_e1', 'foo')) self.assertEqual( { 'href': 'bar.html#property-bar_t1-bar_t1_p1', 'text': 'bar.bar_t1.bar_t1_p1', 'name': 'bar_t1_p1' }, resolver.GetLink('bar.bar_p3.bar_t1_p1', 'foo')) self.assertEqual( { 'href': 'bar.html#property-bar_t1-bar_t1_p1', 'text': 'bar_t1.bar_t1_p1', 'name': 'bar_t1_p1' }, resolver.GetLink('bar_p3.bar_t1_p1', 'bar')) self.assertEqual(None, resolver.GetLink('bar.bar_p3.bar_t2_p1', 'bar')) self.assertEqual(None, resolver.GetLink('bar.bon.bar_e3', 'bar')) self.assertEqual(None, resolver.GetLink('bar_p3', 'baz.bon')) self.assertEqual(None, resolver.GetLink('falafel.faf', 'a')) self.assertEqual(None, resolver.GetLink('bar_p3', 'foo')) self.assertEqual( 'Hello <a href="bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>, ' '<a href="bar.bon.html#property-bar_bon_p3">Bon Bon</a>, ' '<a href="bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>', resolver.ResolveAllLinks( 'Hello $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', 'bar.bon')) self.assertEqual( 'I like <a href="bar.html#property-bar_t1-bar_t1_p1">food</a>.', resolver.ResolveAllLinks( 'I like $ref:[bar.bar_p3.bar_t1_p1 food].', 'foo')) self.assertEqual('Ref <a href="bar.html#type-bon">bon</a>', resolver.ResolveAllLinks('Ref $ref:[bar.bon]', 'bar'))
def testGetLink(self): resolver = ReferenceResolver(_FakeAPIModels(_TEST_DATA), TestObjectStore('test')) self.assertEqual({ 'href': 'foo', 'text': 'foo', 'name': 'foo' }, resolver.GetLink('foo', namespace='baz')) self.assertEqual({ 'href': 'foo#type-foo_t1', 'text': 'foo.foo_t1', 'name': 'foo_t1' }, resolver.GetLink('foo.foo_t1', namespace='baz')) self.assertEqual({ 'href': 'baz#event-baz_e1', 'text': 'baz_e1', 'name': 'baz_e1' }, resolver.GetLink('baz.baz_e1', namespace='baz')) self.assertEqual({ 'href': 'baz#event-baz_e1', 'text': 'baz_e1', 'name': 'baz_e1' }, resolver.GetLink('baz_e1', namespace='baz')) self.assertEqual({ 'href': 'foo#method-foo_f1', 'text': 'foo.foo_f1', 'name': 'foo_f1' }, resolver.GetLink('foo.foo_f1', namespace='baz')) self.assertEqual({ 'href': 'foo#property-foo_p3', 'text': 'foo.foo_p3', 'name': 'foo_p3' }, resolver.GetLink('foo.foo_p3', namespace='baz')) self.assertEqual({ 'href': 'bar.bon#type-bar_bon_t3', 'text': 'bar.bon.bar_bon_t3', 'name': 'bar_bon_t3' }, resolver.GetLink('bar.bon.bar_bon_t3', namespace='baz')) self.assertEqual({ 'href': 'bar.bon#property-bar_bon_p3', 'text': 'bar_bon_p3', 'name': 'bar_bon_p3' }, resolver.GetLink('bar_bon_p3', namespace='bar.bon')) self.assertEqual({ 'href': 'bar.bon#property-bar_bon_p3', 'text': 'bar_bon_p3', 'name': 'bar_bon_p3' }, resolver.GetLink('bar.bon.bar_bon_p3', namespace='bar.bon')) self.assertEqual({ 'href': 'bar#event-bar_e2', 'text': 'bar_e2', 'name': 'bar_e2' }, resolver.GetLink('bar.bar_e2', namespace='bar')) self.assertEqual({ 'href': 'bar#type-bon', 'text': 'bon', 'name': 'bon' }, resolver.GetLink('bar.bon', namespace='bar')) self.assertEqual({ 'href': 'foo#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, resolver.GetLink('foo_t3.foo_t3_e1', namespace='foo')) self.assertEqual({ 'href': 'foo#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, resolver.GetLink('foo.foo_t3.foo_t3_e1', namespace='foo')) self.assertEqual({ 'href': 'foo#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, resolver.GetLink('foo.foo_p1.foo_t3_e1', namespace='foo')) self.assertEqual({ 'href': 'bar#property-bar_t1-bar_t1_p1', 'text': 'bar.bar_t1.bar_t1_p1', 'name': 'bar_t1_p1' }, resolver.GetLink('bar.bar_p3.bar_t1_p1', namespace='foo')) self.assertEqual({ 'href': 'bar#property-bar_t1-bar_t1_p1', 'text': 'bar_t1.bar_t1_p1', 'name': 'bar_t1_p1' }, resolver.GetLink('bar_p3.bar_t1_p1', namespace='bar')) self.assertEqual( None, resolver.GetLink('bar.bar_p3.bar_t2_p1', namespace='bar')) self.assertEqual( None, resolver.GetLink('bar.bon.bar_e3', namespace='bar')) self.assertEqual( None, resolver.GetLink('bar_p3', namespace='baz.bon')) self.assertEqual( None, resolver.GetLink('falafel.faf', namespace='a')) self.assertEqual( None, resolver.GetLink('bar_p3', namespace='foo'))
def testGetLink(self): data_source = FakeAPIDataSource( json.loads(self._ReadLocalFile('fake_data_source.json'))) resolver = ReferenceResolver(data_source, data_source, InMemoryObjectStore('')) self.assertEqual({ 'href': 'foo.html#type-foo_t1', 'text': 'foo.foo_t1' }, resolver.GetLink('baz', 'foo.foo_t1')) self.assertEqual({ 'href': 'baz.html#event-baz_e1', 'text': 'baz_e1' }, resolver.GetLink('baz', 'baz.baz_e1')) self.assertEqual({ 'href': '#event-baz_e1', 'text': 'baz_e1' }, resolver.GetLink('baz', 'baz_e1')) self.assertEqual({ 'href': 'foo.html#method-foo_f1', 'text': 'foo.foo_f1' }, resolver.GetLink('baz', 'foo.foo_f1')) self.assertEqual({ 'href': 'foo.html#property-foo_p3', 'text': 'foo.foo_p3' }, resolver.GetLink('baz', 'foo.foo_p3')) self.assertEqual({ 'href': 'bar.bon.html#type-bar_bon_t3', 'text': 'bar.bon.bar_bon_t3' }, resolver.GetLink('baz', 'bar.bon.bar_bon_t3')) self.assertEqual({ 'href': '#property-bar_bon_p3', 'text': 'bar_bon_p3' }, resolver.GetLink('bar.bon', 'bar_bon_p3')) self.assertEqual({ 'href': 'bar.bon.html#property-bar_bon_p3', 'text': 'bar_bon_p3' }, resolver.GetLink('bar.bon', 'bar.bon.bar_bon_p3')) self.assertEqual({ 'href': 'bar.html#event-bar_e2', 'text': 'bar_e2' }, resolver.GetLink('bar', 'bar.bar_e2')) self.assertEqual({ 'href': 'bar.html#type-bon', 'text': 'bon' }, resolver.GetLink('bar', 'bar.bon')) self.assertEqual({ 'href': '#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1' }, resolver.GetLink('foo', 'foo_t3.foo_t3_e1')) self.assertEqual({ 'href': 'foo.html#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1' }, resolver.GetLink('foo', 'foo.foo_t3.foo_t3_e1')) self.assertEqual( None, resolver.GetLink('bar', 'bar.bon.bar_e3')) self.assertEqual( None, resolver.GetLink('baz.bon', 'bar_p3')) self.assertEqual( None, resolver.GetLink('a', 'falafel.faf')) self.assertEqual( None, resolver.GetLink('foo', 'bar_p3'))
def testGetLink(self): apps_resolver = ReferenceResolver( _FakePlatformBundle().GetAPIModels('apps'), TestObjectStore('apps/test')) extensions_resolver = ReferenceResolver( _FakePlatformBundle().GetAPIModels('extensions'), TestObjectStore('extensions/test')) self.assertEqual({ 'href': 'foo', 'text': 'foo', 'name': 'foo' }, apps_resolver.GetLink('foo', namespace='baz')) self.assertEqual( { 'href': 'foo#type-foo_t1', 'text': 'foo.foo_t1', 'name': 'foo_t1' }, apps_resolver.GetLink('foo.foo_t1', namespace='baz')) self.assertEqual( { 'href': 'baz#event-baz_e1', 'text': 'baz_e1', 'name': 'baz_e1' }, apps_resolver.GetLink('baz.baz_e1', namespace='baz')) self.assertEqual( { 'href': 'baz#event-baz_e1', 'text': 'baz_e1', 'name': 'baz_e1' }, apps_resolver.GetLink('baz_e1', namespace='baz')) self.assertEqual( { 'href': 'foo#method-foo_f1', 'text': 'foo.foo_f1', 'name': 'foo_f1' }, apps_resolver.GetLink('foo.foo_f1', namespace='baz')) self.assertEqual( { 'href': 'foo#property-foo_p3', 'text': 'foo.foo_p3', 'name': 'foo_p3' }, apps_resolver.GetLink('foo.foo_p3', namespace='baz')) self.assertEqual( { 'href': 'bar.bon#type-bar_bon_t3', 'text': 'bar.bon.bar_bon_t3', 'name': 'bar_bon_t3' }, apps_resolver.GetLink('bar.bon.bar_bon_t3', namespace='baz')) self.assertEqual( { 'href': 'bar.bon#property-bar_bon_p3', 'text': 'bar_bon_p3', 'name': 'bar_bon_p3' }, apps_resolver.GetLink('bar_bon_p3', namespace='bar.bon')) self.assertEqual( { 'href': 'bar.bon#property-bar_bon_p3', 'text': 'bar_bon_p3', 'name': 'bar_bon_p3' }, apps_resolver.GetLink('bar.bon.bar_bon_p3', namespace='bar.bon')) self.assertEqual( { 'href': 'bar#event-bar_e2', 'text': 'bar_e2', 'name': 'bar_e2' }, apps_resolver.GetLink('bar.bar_e2', namespace='bar')) self.assertEqual({ 'href': 'bar#type-bon', 'text': 'bon', 'name': 'bon' }, apps_resolver.GetLink('bar.bon', namespace='bar')) self.assertEqual( { 'href': 'foo#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, apps_resolver.GetLink('foo_t3.foo_t3_e1', namespace='foo')) self.assertEqual( { 'href': 'foo#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, apps_resolver.GetLink('foo.foo_t3.foo_t3_e1', namespace='foo')) self.assertEqual( { 'href': 'foo#event-foo_t3-foo_t3_e1', 'text': 'foo_t3.foo_t3_e1', 'name': 'foo_t3_e1' }, apps_resolver.GetLink('foo.foo_p1.foo_t3_e1', namespace='foo')) self.assertEqual( { 'href': 'bar#property-bar_t1-bar_t1_p1', 'text': 'bar.bar_t1.bar_t1_p1', 'name': 'bar_t1_p1' }, apps_resolver.GetLink('bar.bar_p3.bar_t1_p1', namespace='foo')) # Test extensions_resolver. self.assertEqual( { 'href': 'bar#property-bar_t1-bar_t1_p1', 'text': 'bar.bar_t1.bar_t1_p1', 'name': 'bar_t1_p1' }, extensions_resolver.GetLink('bar.bar_p3.bar_t1_p1', namespace='foo')) self.assertEqual( { 'href': 'bar#property-bar_t1-bar_t1_p1', 'text': 'bar_t1.bar_t1_p1', 'name': 'bar_t1_p1' }, apps_resolver.GetLink('bar_p3.bar_t1_p1', namespace='bar')) self.assertEqual( None, apps_resolver.GetLink('bar.bar_p3.bar_t2_p1', namespace='bar')) self.assertEqual( None, apps_resolver.GetLink('bar.bon.bar_e3', namespace='bar')) self.assertEqual(None, apps_resolver.GetLink('bar_p3', namespace='baz.bon')) self.assertEqual(None, apps_resolver.GetLink('falafel.faf', namespace='a')) self.assertEqual(None, apps_resolver.GetLink('bar_p3', namespace='foo')) # Exists in apps but not extensions. self.assertEqual( None, extensions_resolver.GetLink('foo.foo_p3', namespace='baz'))