How to use the make-plural-compiler/src/compiler.rules function in make-plural-compiler

To help you get started, we’ve selected a few make-plural-compiler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eemeli / make-plural / test / plural-data.js View on Github external
it('has autogenerated tests', function() {
    const mpc = new MakePlural(lc, opt)
    expect(() => mpc.compile()).to.not.throw()
    expect(mpc.tests[type]).to.not.be.empty
  })

  it('is included in the output', function() {
    expect(getPlural(lc)).to.be.an.instanceOf(Function)
  })

  var mpc = new MakePlural(lc, opt)
  var mp = mpc.compile()
  for (var cat in mpc.tests[type]) {
    describe(
      cat + ': ' + MakePlural.rules[type][lc]['pluralRule-count-' + cat],
      function() {
        ;(function(cat) {
          it('Live data', function() {
            var test = mpc.tests.testCat.bind(mpc.tests)
            expect(() => test(type, cat, mp)).to.not.throw()
          })
          it('Output', function() {
            var test = mpc.tests.testCat.bind(mpc.tests)
            expect(() => test(type, cat, getPlural(lc))).to.not.throw()
          })
        })(cat)
      }
    )
  }
}
github eemeli / make-plural / test / compiler.js View on Github external
it('should not validate bad functions', function() {
      var cldr = {
          supplemental: {
            'plurals-type-cardinal': {
              xx: {
                'pluralRule-count-one': 'n = 1 @integer 2',
                'pluralRule-count-other': ''
              }
            }
          }
        },
        prevRules = MakePlural.rules
      MakePlural.load(cldr)
      var mpc = new MakePlural('xx')
      var mp = mpc.compile()
      expect(mpc.test).to.throw(/self-test failed/)
      MakePlural.rules = prevRules
    })
  })
github eemeli / make-plural / test / compiler.js View on Github external
it('should load custom CLDR data', function() {
      var cldr = {
        supplemental: {
          'plurals-type-cardinal': {
            xx: {
              'pluralRule-count-one':
                'n = 1 @integer 1 @decimal 1.0, 1.00, 1.000, 1.0000',
              'pluralRule-count-other':
                ' @integer 0, 2~16, 100, 1000, … @decimal 0.0~0.9, 1.1~1.6, 10.0, 100.0, 1000.0, …'
            }
          }
        }
      }
      MakePlural.load(cldr)
      expect(MakePlural.rules).to.have.keys('cardinal', 'ordinal')
      expect(MakePlural.rules.cardinal).to.have.key('xx')
    })
    it('should load default CLDR data', function() {
github eemeli / make-plural / test / compiler.js View on Github external
it('should load default CLDR data', function() {
      expect(() => MakePlural.load(cardinalData, ordinalData)).to.not.throw()
      expect(MakePlural.rules).to.have.keys('cardinal', 'ordinal')
      expect(MakePlural.rules.cardinal).to.not.have.any.key('xx')
      expect(MakePlural.rules.cardinal).to.have.any.key('en')
      expect(MakePlural.rules.ordinal).to.have.any.key('en')
    })
    it('should return MakePlural', function() {
github eemeli / make-plural / test / compiler.js View on Github external
var cldr = {
          supplemental: {
            'plurals-type-cardinal': {
              xx: {
                'pluralRule-count-one': 'n = 1 @integer 2',
                'pluralRule-count-other': ''
              }
            }
          }
        },
        prevRules = MakePlural.rules
      MakePlural.load(cldr)
      var mpc = new MakePlural('xx')
      var mp = mpc.compile()
      expect(mpc.test).to.throw(/self-test failed/)
      MakePlural.rules = prevRules
    })
  })