Advertisement
Guest User

Untitled

a guest
Mar 11th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. describe('Test "other regions" functions', () => {
  4.     const titles = [
  5.       {
  6.         scrapedText: 'Byggmester Bob - Kan det Fikses? [SLES-03563]',
  7.         expect: 'Byggmester Bob - Kan det Fikses?',
  8.       }, {
  9.         scrapedText: 'A Sangue Freddo [SCES-02152 & SCES-12152]',
  10.         expect: 'A Sangue Freddo',
  11.       }, {
  12.         scrapedText: 'Asterix [All your Cartoon Favourites Version] (SLES-01748)',
  13.         expect: 'Asterix [All your Cartoon Favourites Version]',
  14.       }, {
  15.         scrapedText: 'Asterix (All your Cartoon Favourites Version) [SLES-01748]',
  16.         expect: 'Asterix (All your Cartoon Favourites Version)',
  17.       }, {
  18.         scrapedText: 'Final Fantasy Collection Anniversary Package [SLPS-01945~7]',
  19.         expect: 'Final Fantasy Collection Anniversary Package',
  20.       }, {
  21.         scrapedText: 'Final Fantasy VIII [SLES-02084, SLES-12084, SLES-22084 & SLES-32084]',
  22.         expect: 'Final Fantasy VIII',
  23.       }, {
  24.         scrapedText: 'Final Fantasy VIII [Ultimate Hits] [SLPM-87384~7]',
  25.         expect: 'Final Fantasy VIII [Ultimate Hits]',
  26.       },
  27.     ];
  28.  
  29.     new Using(titles).describe('check response from getTitleFromOtherRegion():', (test: any) => {
  30.       it(` check title for: ${test.scrapedText}`, () => {
  31.         const returnedTitle = game.getTitleFromOtherRegion(test.scrapedText);
  32.         expect(returnedTitle).toBe(test.expect);
  33.       });
  34.     });
  35.   });
  36.  
  37.  
  38. // somewhere on game.class.ts
  39. private getTitleFromOtherRegion(gameTitle: string): string {
  40.     // let title = gameTitle.remove('img').text();
  41.     let title = gameTitle;
  42.     title = title.trim();
  43.     title = this.getLastCharacterOfString(title, '-') ? title.slice(0, -1) : title;
  44.     title = title.trim();
  45.     const titleRegexp = /\(([^)]+)\)/gm.exec(title);
  46.     const titleRegexpSquare: string[] | null = title.match(/\[([^\]]+)\]/gm);
  47.  
  48.     if (titleRegexpSquare && titleRegexp) {
  49.  
  50.     }
  51.  
  52.     if (titleRegexpSquare && titleRegexp === null) {
  53.       if (titleRegexpSquare.length > 1) {
  54.         return `${title.split(titleRegexpSquare[0])[0].trim()} ${titleRegexpSquare[0]}`;
  55.       }
  56.  
  57.       return title.split(titleRegexpSquare[0])[0].trim();
  58.     }
  59.  
  60.     return title;
  61.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement