예제 #1
0
 public void ExcessivelyShortIdentifiersTestPos()
 {
     detector.code = @"function start(x) {
         var tmp = 20;
             function foo(y)
             {
                 ++tmp;
                 function mid(z)
                 {
                     tmp -= 10;
                     function end(q)
                     {
                         document.write(x + y + z + q + tmp);
                     }
                     end(1);
                 }
                 mid(3);
             }
             foo(10);
         }
         start(2);
     ";
     detector.ASTAnalysis();
     Assert.That(smell.Occurrences.Count, Is.EqualTo(1));
 }
예제 #2
0
        public void ExcessivelyShortIdentifiersTestPos()
        {
            detector.code = @"function showChapter(chapter, tutorial) {
                if (chapter.orderIndex == 1)
                {
                    this.redirectToRoot()
                }
                let higherChapters = chapter.items.filter(item => item.higher)
                let lowerTutorials = chapter.items.filter(item => !item.higher)
                let title = chapter.title
                let description = chapter.description
                if (chapter.lowerItem)
                {
                    this.nextPath = this.getChapterPath(this.tutorial, chapter.lowerItem)
                    this.nextLink = this.nextPath
                }
                else if (!!tutorial.pathId && !!lowerTutorials)
                {
                    this.nextPath = this.getTutorialPath(lowerTutorials[0])
                    this.nextLink = this.nextPath
                }
                else if (chapter.last && !tutorial.footLinks.length > 0)
                    this.nextPath = tutorial.footLinks.url
                if (higherChapters.length === 0)
                    this.prevLink = this.getChapterPath(tutorial, higherChapters)
                else if (!!tutorial.pathId && tutorial.higherItem)
                {
                    let higherTutorial = tutorial.higherItem
                    lastChapter = higherTutorial.chapters[higherTutorial.chapters.length - 1]
          
                    if (lastChapter.orderIndex == 1)
                        this.prevLink = this.getTutorialPath(higherTutorial)
                    else
                        this.prevLink = this.getChapterPath(higherTutorial, higherChapters)
                }

                this.storeProps = {
                    checkableType: 'Chapter',
                    checkableId: chapter.id,
                    checkboxes: this.signedIn ? currentUser.getCheckboxesFor(chapter) : []
                }
                this.setStore()
                this.modal = this.getModalChapter(chapter) || this.getModalTutorial(tutorial)
            }";
            detector.ASTAnalysis();
            Assert.That(smell.Occurrences.Count, Is.EqualTo(1));
        }
 public void SmallSwitchStatementTestPos()
 {
     detector.code = @"const expr = 'Papayas';
         switch (expr) {
             case 'Oranges':
                 console.log('Oranges are $0.59 a pound.');
                 break;
             case 'Apples':
                 console.log('Apples are $0.31 a pound.');
                 break;
             default:
                 console.log(`Sorry, we are out of ${expr}.`);
         }
     ";
     detector.ASTAnalysis();
     Assert.That(smell.Occurrences.Count, Is.EqualTo(1));
 }
예제 #4
0
 public void ExcessivelyLongIdentifiersTestPos()
 {
     detector.code = "var red_long_sleeve_basketballShirt  = 49.50;";
     detector.ASTAnalysis();
     Assert.That(smell.Occurrences.Count, Is.EqualTo(1));
 }
 public void ExcessivelyShortIdentifiersTestPos()
 {
     detector.code = "var xy = 1;";
     detector.ASTAnalysis();
     Assert.That(smell.Occurrences.Count, Is.EqualTo(1));
 }
 public void ExcessivelyShortIdentifiersTestPos()
 {
     detector.code = "x.add(3).subtract(2).multiply(6).divide(5).add(1).print();";
     detector.ASTAnalysis();
     Assert.That(smell.Occurrences.Count, Is.EqualTo(1));
 }
 public void TooManyParametersFunctionTestPos()
 {
     detector.code = "function name(par1, par2, par3, par4, par5, par6) { return 2; }";
     detector.ASTAnalysis();
     Assert.That(smell.Occurrences.Count, Is.EqualTo(1));
 }