當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript url_resolver.UrlResolver類代碼示例

本文整理匯總了TypeScript中@angular/compiler/src/url_resolver.UrlResolver的典型用法代碼示例。如果您正苦於以下問題:TypeScript UrlResolver類的具體用法?TypeScript UrlResolver怎麽用?TypeScript UrlResolver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了UrlResolver類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

    describe('asset urls', () => {
      let resolver: UrlResolver;
      beforeEach(() => { resolver = createOfflineCompileUrlResolver(); });

      it('should resolve package: urls into asset: urls', () => {
        expect(resolver.resolve(null, 'package:somePkg/somePath'))
            .toEqual('asset:somePkg/lib/somePath');
      });
    });
開發者ID:AlmogShaul,項目名稱:angular,代碼行數:9,代碼來源:url_resolver_spec.ts

示例2: inject

 inject([UrlResolver], (resolver: UrlResolver) => {
   if (!IS_DART) {
     expect(resolver.resolve(null, 'package:file')).toEqual('/file');
   }
 }));
開發者ID:BharatBhatiya,項目名稱:test,代碼行數:5,代碼來源:url_resolver_spec.ts

示例3: describe

  describe('UrlResolver', () => {
    let resolver = new UrlResolver();

    describe('absolute base url', () => {
      it('should add a relative path to the base url', () => {
        expect(resolver.resolve('http://www.foo.com', 'bar')).toEqual('http://www.foo.com/bar');
        expect(resolver.resolve('http://www.foo.com/', 'bar')).toEqual('http://www.foo.com/bar');
        expect(resolver.resolve('http://www.foo.com', './bar')).toEqual('http://www.foo.com/bar');
        expect(resolver.resolve('http://www.foo.com/', './bar')).toEqual('http://www.foo.com/bar');
      });

      it('should replace the base path', () => {
        expect(resolver.resolve('http://www.foo.com/baz', 'bar')).toEqual('http://www.foo.com/bar');
        expect(resolver.resolve('http://www.foo.com/baz', './bar'))
            .toEqual('http://www.foo.com/bar');
      });

      it('should append to the base path', () => {
        expect(resolver.resolve('http://www.foo.com/baz/', 'bar'))
            .toEqual('http://www.foo.com/baz/bar');
        expect(resolver.resolve('http://www.foo.com/baz/', './bar'))
            .toEqual('http://www.foo.com/baz/bar');
      });

      it('should support ".." in the path', () => {
        expect(resolver.resolve('http://www.foo.com/baz/', '../bar'))
            .toEqual('http://www.foo.com/bar');
        expect(resolver.resolve('http://www.foo.com/1/2/3/', '../../bar'))
            .toEqual('http://www.foo.com/1/bar');
        expect(resolver.resolve('http://www.foo.com/1/2/3/', '../biz/bar'))
            .toEqual('http://www.foo.com/1/2/biz/bar');
        expect(resolver.resolve('http://www.foo.com/1/2/baz', '../../bar'))
            .toEqual('http://www.foo.com/bar');
      });

      it('should ignore the base path when the url has a scheme', () => {
        expect(resolver.resolve('http://www.foo.com', 'http://www.bar.com'))
            .toEqual('http://www.bar.com');
      });

      it('should support absolute urls', () => {
        expect(resolver.resolve('http://www.foo.com', '/bar')).toEqual('http://www.foo.com/bar');
        expect(resolver.resolve('http://www.foo.com/', '/bar')).toEqual('http://www.foo.com/bar');
        expect(resolver.resolve('http://www.foo.com/baz', '/bar'))
            .toEqual('http://www.foo.com/bar');
        expect(resolver.resolve('http://www.foo.com/baz/', '/bar'))
            .toEqual('http://www.foo.com/bar');
      });
    });

    describe('relative base url', () => {
      it('should add a relative path to the base url', () => {
        expect(resolver.resolve('foo/', './bar')).toEqual('foo/bar');
        expect(resolver.resolve('foo/baz', './bar')).toEqual('foo/bar');
        expect(resolver.resolve('foo/baz', 'bar')).toEqual('foo/bar');

      });

      it('should support ".." in the path', () => {
        expect(resolver.resolve('foo/baz', '../bar')).toEqual('bar');
        expect(resolver.resolve('foo/baz', '../biz/bar')).toEqual('biz/bar');
      });

      it('should support absolute urls', () => {
        expect(resolver.resolve('foo/baz', '/bar')).toEqual('/bar');
        expect(resolver.resolve('foo/baz/', '/bar')).toEqual('/bar');
      });

      it('should not resolve urls against the baseUrl when the url contains a scheme', () => {
        resolver = new UrlResolver('my_packages_dir');
        expect(resolver.resolve('base/', 'package:file')).toEqual('my_packages_dir/file');
        expect(resolver.resolve('base/', 'http:super_file')).toEqual('http:super_file');
        expect(resolver.resolve('base/', './mega_file')).toEqual('base/mega_file');
      });
    });

    describe('packages', () => {
      it('should resolve a url based on the application package', () => {
        resolver = new UrlResolver('my_packages_dir');
        expect(resolver.resolve(null !, 'package:some/dir/file.txt'))
            .toEqual('my_packages_dir/some/dir/file.txt');
        expect(resolver.resolve(null !, 'some/dir/file.txt')).toEqual('some/dir/file.txt');
      });

      it('should contain a default value of "/" when nothing is provided',
         inject([UrlResolver], (resolver: UrlResolver) => {
           expect(resolver.resolve(null !, 'package:file')).toEqual('/file');
         }));

      it('should resolve a package value when present within the baseurl', () => {
        resolver = new UrlResolver('/my_special_dir');
        expect(resolver.resolve('package:some_dir/', 'matias.html'))
            .toEqual('/my_special_dir/some_dir/matias.html');
      });
    });

    describe('corner and error cases', () => {
      it('should encode URLs before resolving',
         () => {
           expect(resolver.resolve('foo/baz', `<p #p>Hello
//.........這裏部分代碼省略.........
開發者ID:Cammisuli,項目名稱:angular,代碼行數:101,代碼來源:url_resolver_spec.ts

示例4: it

 it('should support absolute urls', () => {
   expect(resolver.resolve('http://www.foo.com', '/bar')).toEqual('http://www.foo.com/bar');
   expect(resolver.resolve('http://www.foo.com/', '/bar')).toEqual('http://www.foo.com/bar');
   expect(resolver.resolve('http://www.foo.com/baz', '/bar'))
       .toEqual('http://www.foo.com/bar');
   expect(resolver.resolve('http://www.foo.com/baz/', '/bar'))
       .toEqual('http://www.foo.com/bar');
 });
開發者ID:Cammisuli,項目名稱:angular,代碼行數:8,代碼來源:url_resolver_spec.ts


注:本文中的@angular/compiler/src/url_resolver.UrlResolver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。