|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +/* eslint-env mocha */ |
| 4 | +/* eslint-disable no-unused-expressions */ |
| 5 | + |
| 6 | +var espree = require('espree'); |
| 7 | +var expect = require('chai').expect; |
| 8 | + |
| 9 | +var utils = require('../../rules/utils/utils'); |
| 10 | + |
| 11 | + |
| 12 | +describe('convertPrefixToRegex', function() { |
| 13 | + it('should not handle non-string objects', function() { |
| 14 | + var obj = {}; |
| 15 | + expect(utils.convertPrefixToRegex(obj) === obj).to.be.true; |
| 16 | + }); |
| 17 | + |
| 18 | + xit('should not convert a string ending and starting with a / to a Regex', function() { |
| 19 | + expect(utils.convertPrefixToRegex('/app/'.source)).to.equal('app.*'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should not convert a regulat string a Regex', function() { |
| 23 | + expect(utils.convertPrefixToRegex('app').source).to.equal('app.*'); |
| 24 | + }); |
| 25 | +}); |
| 26 | + |
| 27 | +describe('convertStringToRegex', function() { |
| 28 | + xit('should not convert a string ending and starting with a / to a Regex', function() { |
| 29 | + expect(utils.convertStringToRegex('/app/'.source)).to.equal('app'); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should not convert a regulat string a Regex', function() { |
| 33 | + expect(utils.convertStringToRegex('app').source).to.equal('app'); |
| 34 | + }); |
| 35 | +}); |
| 36 | + |
| 37 | +describe('isAngularControllerDeclaration', function() { |
| 38 | + it('should return true if the function call chained from a module definition declares a controller', function() { |
| 39 | + var ast = espree.parse('angular.module("", []).controller("", function() {});'); |
| 40 | + expect(utils.isAngularControllerDeclaration(ast.body[0].expression)).to.be.true; |
| 41 | + }); |
| 42 | + |
| 43 | + it('should return true if the function call chained from a module getter declares a controller', function() { |
| 44 | + var ast = espree.parse('angular.module("").controller("", function() {});'); |
| 45 | + expect(utils.isAngularControllerDeclaration(ast.body[0].expression)).to.be.true; |
| 46 | + }); |
| 47 | + |
| 48 | + xit('should return false if a controller function from some variable is called', function() { |
| 49 | + var ast = espree.parse('app.controller("", function() {});'); |
| 50 | + expect(utils.isAngularControllerDeclaration(ast.body[0].expression)).to.be.false; |
| 51 | + }); |
| 52 | + |
| 53 | + it('should return true if a referenced angular module declares a controller', function() { |
| 54 | + var ast = espree.parse('var app = angular.module("");app.controller("", function() {});'); |
| 55 | + expect(utils.isAngularControllerDeclaration(ast.body[1].expression)).to.be.true; |
| 56 | + }); |
| 57 | + |
| 58 | + it('should return false if too few arguments are passed', function() { |
| 59 | + var ast = espree.parse('angular.module("").controller("");'); |
| 60 | + expect(utils.isAngularControllerDeclaration(ast.body[0].expression)).to.be.false; |
| 61 | + }); |
| 62 | +}); |
| 63 | + |
| 64 | +describe('isAngularModuleDeclaration', function() { |
| 65 | + it('should return true for an Angular module declaration', function() { |
| 66 | + var ast = espree.parse('angular.module("", []);'); |
| 67 | + expect(utils.isAngularModuleDeclaration(ast.body[0].expression)).to.be.true; |
| 68 | + }); |
| 69 | + |
| 70 | + it('should return false for an Angular module getter', function() { |
| 71 | + var ast = espree.parse('angular.module("");'); |
| 72 | + expect(utils.isAngularModuleDeclaration(ast.body[0].expression)).to.be.false; |
| 73 | + }); |
| 74 | +}); |
| 75 | + |
| 76 | +describe('isAngularModuleGetter', function() { |
| 77 | + xit('should return false for an Angular module declaration', function() { |
| 78 | + var ast = espree.parse('angular.module("", []);'); |
| 79 | + expect(utils.isAngularModuleGetter(ast.body[0].expression)).to.be.false; |
| 80 | + }); |
| 81 | + |
| 82 | + it('should return true for an Angular module getter', function() { |
| 83 | + var ast = espree.parse('angular.module("");'); |
| 84 | + expect(utils.isAngularModuleGetter(ast.body[0].expression)).to.be.true; |
| 85 | + }); |
| 86 | +}); |
| 87 | + |
| 88 | +describe('isAngularRunSection', function() { |
| 89 | + xit('should return true if the call defines a run function', function() { |
| 90 | + var ast = espree.parse('angular.module("").run(function() {});'); |
| 91 | + expect(utils.isAngularRunSection(ast.body[0].expression)).to.be.true; |
| 92 | + }); |
| 93 | + |
| 94 | + xit('should return false is a run is called on a random object', function() { |
| 95 | + var ast = espree.parse('app.run();'); |
| 96 | + expect(utils.isAngularRunSection(ast.body[0].expression)).to.be.false; |
| 97 | + }); |
| 98 | +}); |
0 commit comments