Skip to content
Browse files

Removing javascript compiler stuff, which has been moved to twitter-c…

…ldr-js
  • Loading branch information...
1 parent d555c15 commit 1cfb0d919cc3dbd62f49badaa5737bc881a981ee Cameron Dutro committed Aug 21, 2012
Showing with 3 additions and 1,881 deletions.
  1. +1 −29 README.md
  2. +0 −25 Rakefile
  3. +0 −1 js/.jasmine-headless-webkit
  4. +0 −42 js/lib/compiler.rb
  5. +0 −14 js/lib/mustache/bundle.coffee
  6. +0 −240 js/lib/mustache/calendars/datetime.coffee
  7. +0 −52 js/lib/mustache/calendars/timespan.coffee
  8. +0 −179 js/lib/mustache/numbers/numbers.coffee
  9. +0 −14 js/lib/mustache/plurals/rules.coffee
  10. +0 −27 js/lib/mustache/shared/currencies.coffee
  11. +0 −18 js/lib/renderers/base.rb
  12. +0 −18 js/lib/renderers/bundle.rb
  13. +0 −34 js/lib/renderers/calendars/datetime_renderer.rb
  14. +0 −39 js/lib/renderers/calendars/timespan_renderer.rb
  15. +0 −31 js/lib/renderers/numbers/numbers_renderer.rb
  16. +0 −93 js/lib/renderers/plurals/rules/plural_rules_compiler.rb
  17. +0 −26 js/lib/renderers/plurals/rules/plural_rules_renderer.rb
  18. +0 −23 js/lib/renderers/shared/currencies_renderer.rb
  19. +0 −87 js/lib/twitter_cldr_js.rb
  20. +0 −418 js/spec/js/calendars/datetime_spec.js
  21. +0 −91 js/spec/js/calendars/timespan_spec.js
  22. +0 −34 js/spec/js/numbers/currency_spec.js
  23. +0 −24 js/spec/js/numbers/decimal_spec.js
  24. +0 −23 js/spec/js/numbers/helpers/fraction_spec.js
  25. +0 −100 js/spec/js/numbers/helpers/integer_spec.js
  26. +0 −70 js/spec/js/numbers/number_spec.js
  27. +0 −22 js/spec/js/numbers/percent_spec.js
  28. +0 −28 js/spec/js/plurals/plural_rules_spec.js
  29. +0 −8 js/spec/js/support/jasmine.yml
  30. +0 −56 js/spec/rb/renderers/plurals/plural_rules_compiler_spec.rb
  31. +0 −13 js/spec/rb/spec_helper.rb
  32. +2 −2 twitter_cldr.gemspec
View
30 README.md
@@ -512,35 +512,7 @@ Tests are written in RSpec using RR as the mocking framework.
## JavaScript Support
-TwitterCLDR currently supports localization of dates and times in JavaScript. More awesome features are coming soon. See [http://github.com/twitter/twitter-cldr-js](http://github.com/twitter/twitter-cldr-js) for details.
-
-### Generating the JavaScript
-
-You can automatically generate the JavaScript version of TwitterCLDR using this Rubygem. Here's the one-liner:
-
-`bundle exec rake js:build OUTPUT_DIR=/path/to/desired/output/location`
-
-If you'd like to customize the generated output further, you'll need to require the `TwitterCldr::Js` namespace. You can choose the locales to export and whether to export a minified version alongside the full version for each locale.
-
-```ruby
-require 'twitter_cldr'
-
-TwitterCldr.require_js # require JavaScript environment
-TwitterCldr::Js.output_dir = "/path/to/output/location"
-TwitterCldr::Js.make(:locales => [:de, :sv, :ja, :ar], # generate files for German, Swedish,
- :minify => true) # Japanese, and Arabic
-TwitterCldr::Js.install # copy files to output directory
-```
-
-### Running Tests (JS)
-
-A JavaScript test suite comes with twitter-cldr-rb. You'll need to install the Qt libs to be able to run the suite, as it uses [jasmine](https://github.com/pivotal/jasmine-gem) and [jasmine-headless-webkit](http://johnbintz.github.com/jasmine-headless-webkit/).
-
-1. Install qt (eg. `brew install qt`, `sudo apt-get install qt4`, etc)
-2. Run `bundle`
-3. Run `bundle exec rake js:test`
-
-The tests are located in `js/spec` and look similar to RSpec tests.
+TwitterCLDR currently supports localization of dates and times in JavaScript via the twitter-cldr-js gem. More awesome features are coming soon. See [http://github.com/twitter/twitter-cldr-js](http://github.com/twitter/twitter-cldr-js) for details.
## Authors
View
25 Rakefile
@@ -113,28 +113,3 @@ namespace :update do
TwitterCldr::Resources::CanonicalCompositionsUpdater.new('./resources/unicode_data').update
end
end
-
-namespace :js do
- desc 'Build JS files'
- task :build do
- TwitterCldr.require_js
- FileUtils.mkdir_p(TwitterCldr::Js.build_dir)
- TwitterCldr::Js.output_dir = File.expand_path(ENV["OUTPUT_DIR"])
- TwitterCldr::Js.make(:locales => TwitterCldr.supported_locales)
- TwitterCldr::Js.install
- end
-
- desc 'Run JS specs'
- task :test do
- TwitterCldr.require_js
- FileUtils.mkdir_p(TwitterCldr::Js.build_dir)
- TwitterCldr::Js.make(:locales => [:en])
- puts "Running JavaScript tests (Jasmine)..."
- TwitterCldr::Js.test
- FileUtils.rm_rf(TwitterCldr::Js.build_dir)
- puts "\nRunning Ruby tests (RSpec)..."
- Dir.chdir(File.join(File.dirname(__FILE__), "js")) do
- Rake::Task["spec"].execute
- end
- end
-end
View
1 js/.jasmine-headless-webkit
@@ -1 +0,0 @@
--j spec/js/support/jasmine.yml
View
42 js/lib/compiler.rb
@@ -1,42 +0,0 @@
-# encoding: UTF-8
-
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-module TwitterCldr
- module Js
- class Compiler
- def initialize(options = {})
- @locales = options[:locales] || TwitterCldr.supported_locales
- @features = options[:features] || renderers.keys
- end
-
- def compile
- @locales.each do |locale|
- contents = ""
-
- @features.each do |feature|
- renderer_const = renderers[feature]
- contents << renderer_const.new(:locale => locale).render if renderer_const
- end
-
- bundle = TwitterCldr::Js::Renderers::Bundle.new
- bundle[:contents] = contents
- yield CoffeeScript.compile(bundle.render, :bare => true), TwitterCldr.twitter_locale(locale) if block_given?
- end
- end
-
- private
-
- def renderers
- @renderers ||= {
- :plural_rules => TwitterCldr::Js::Renderers::PluralRules::PluralRulesRenderer,
- :timespan => TwitterCldr::Js::Renderers::Calendars::TimespanRenderer,
- :datetime => TwitterCldr::Js::Renderers::Calendars::DateTimeRenderer,
- :numbers => TwitterCldr::Js::Renderers::Numbers::NumbersRenderer,
- :currencies => TwitterCldr::Js::Renderers::Shared::CurrenciesRenderer
- }
- end
- end
- end
-end
View
14 js/lib/mustache/bundle.coffee
@@ -1,14 +0,0 @@
-###
-// Copyright 2012 Twitter, Inc
-// http://www.apache.org/licenses/LICENSE-2.0
-
-// TwitterCLDR (JavaScript) v{{version}}
-// Authors: Cameron Dutro [@camertron]
- Kirill Lashuk [@KL_7]
- portions by Sven Fuchs [@svenfuchs]
-// Homepage: https://twitter.com
-// Description: Provides date, time, number, and list formatting functionality for various Twitter-supported locales in Javascript.
-###
-
-TwitterCldr = {}
-{{{contents}}}
View
240 js/lib/mustache/calendars/datetime.coffee
@@ -1,240 +0,0 @@
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-TwitterCldr.DateTimeFormatter = class DateTimeFormatter
- constructor: ->
- @tokens = `{{{tokens}}}`
- @calendar = `{{{calendar}}}`
- @weekday_keys = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]
- @methods = # ignoring u, l, g, j, A
- 'G': 'era'
- 'y': 'year'
- 'Y': 'year_of_week_of_year'
- 'Q': 'quarter'
- 'q': 'quarter_stand_alone'
- 'M': 'month'
- 'L': 'month_stand_alone'
- 'w': 'week_of_year'
- 'W': 'week_of_month'
- 'd': 'day'
- 'D': 'day_of_month'
- 'F': 'day_of_week_in_month'
- 'E': 'weekday'
- 'e': 'weekday_local'
- 'c': 'weekday_local_stand_alone'
- 'a': 'period'
- 'h': 'hour'
- 'H': 'hour'
- 'K': 'hour'
- 'k': 'hour'
- 'm': 'minute'
- 's': 'second'
- 'S': 'second_fraction'
- 'z': 'timezone'
- 'Z': 'timezone'
- 'v': 'timezone_generic_non_location'
- 'V': 'timezone_metazone'
-
- format: (obj, options) ->
- format_token = (token) =>
- result = ""
-
- switch token.type
- when "pattern"
- return this.result_for_token(token, obj)
- else
- if token.value.length > 0 && token.value[0] == "'" && token.value[token.value.length - 1] == "'"
- return token.value.substring(1, token.value.length - 1)
- else
- return token.value
-
- tokens = this.get_tokens(obj, options)
- return (format_token(token) for token in tokens).join("")
-
- get_tokens: (obj, options) ->
- return @tokens[options.format || "date_time"][options.type || "default"]
-
- result_for_token: (token, date) ->
- return this[@methods[token.value[0]]](date, token.value, token.value.length)
-
- era: (date, pattern, length) ->
- switch length
- when 1, 2, 3
- choices = @calendar["eras"]["abbr"]
- else
- choices = @calendar["eras"]["name"]
-
- index = if (date.getFullYear() < 0) then 0 else 1
- return choices[index]
-
- year: (date, pattern, length) ->
- year = date.getFullYear().toString()
-
- if length == 2
- if year.length != 1
- year = year.slice(-2)
-
- if length > 1
- year = ("0000" + year).slice(-length)
-
- return year
-
- year_of_week_of_year: (date, pattern, length) ->
- throw 'not implemented'
-
- day_of_week_in_month: (date, pattern, length) -> # e.g. 2nd Wed in July
- throw 'not implemented'
-
- quarter: (date, pattern, length) ->
- # the bitwise OR is used here to truncate the decimal produced by the / 3
- quarter = ((date.getMonth() / 3) | 0) + 1
-
- switch length
- when 1
- return quarter.toString()
- when 2
- return ("0000" + quarter.toString()).slice(-length)
- when 3
- return @calendar.quarters.format.abbreviated[quarter]
- when 4
- return @calendar.quarters.format.wide[quarter]
-
- quarter_stand_alone: (date, pattern, length) ->
- quarter = (date.getMonth() - 1) / 3 + 1
-
- switch length
- when 1
- return quarter.toString()
- when 2
- return ("0000" + quarter.toString()).slice(-length)
- when 3
- throw 'not yet implemented (requires cldr\'s "multiple inheritance")'
- when 4
- throw 'not yet implemented (requires cldr\'s "multiple inheritance")'
- when 5
- return @calendar.quarters['stand-alone'].narrow[quarter]
-
- month: (date, pattern, length) ->
- month_str = (date.getMonth() + 1).toString()
-
- switch length
- when 1
- return month_str
- when 2
- return ("0000" + month_str).slice(-length)
- when 3
- return @calendar.months.format.abbreviated[month_str]
- when 4
- return @calendar.months.format.wide[month_str]
- when 5
- throw 'not yet implemented (requires cldr\'s "multiple inheritance")'
- else
- throw "Unknown date format"
-
- month_stand_alone: (date, pattern, length) ->
- switch length
- when 1
- return date.getMonth().toString()
- when 2
- return ("0000" + date.getMonth().toString()).slice(-length)
- when 3
- throw 'not yet implemented (requires cldr\'s "multiple inheritance")'
- when 4
- throw 'not yet implemented (requires cldr\'s "multiple inheritance")'
- when 5
- return @calendar.months['stand-alone'].narrow[date.month]
- else
- throw "Unknown date format"
-
- day: (date, pattern, length) ->
- switch length
- when 1
- return date.getDate().toString()
- when 2
- return ("0000" + date.getDate().toString()).slice(-length)
-
- weekday: (date, pattern, length) ->
- key = @weekday_keys[date.getDay()]
-
- switch length
- when 1, 2, 3
- return @calendar.days.format.abbreviated[key]
- when 4
- return @calendar.days.format.wide[key]
- when 5
- return @calendar.days['stand-alone'].narrow[key]
-
- weekday_local: (date, pattern, length) ->
- # "Like E except adds a numeric value depending on the local starting day of the week"
- # CLDR does not contain data as to which day is the first day of the week, so we will assume Monday (Ruby default)
- switch length
- when 1, 2
- day = date.getDay()
- return (if day == 0 then "7" else day.toString())
- else
- return this.weekday(date, pattern, length)
-
- weekday_local_stand_alone: (date, pattern, length) ->
- switch length
- when 1
- return this.weekday_local(date, pattern, length)
- else
- return this.weekday(date, pattern, length)
-
- period: (time, pattern, length) ->
- if time.getHours() > 11
- return @calendar.periods.format.wide["pm"]
- else
- return @calendar.periods.format.wide["am"]
-
- hour: (time, pattern, length) ->
- hour = time.getHours()
-
- switch pattern[0]
- when 'h'
- if hour > 12
- hour = hour - 12
- else if hour == 0
- hour = 12
- when 'K'
- if hour > 11
- hour = hour - 12
- when 'k'
- if hour == 0
- hour = 24
-
- if length == 1
- return hour.toString()
- else
- return ("000000" + hour.toString()).slice(-length)
-
- minute: (time, pattern, length) ->
- if length == 1
- return time.getMinutes().toString()
- else
- return ("000000" + time.getMinutes().toString()).slice(-length)
-
- second: (time, pattern, length) ->
- if length == 1
- return time.getSeconds().toString()
- else
- return ("000000" + time.getSeconds().toString()).slice(-length)
-
- second_fraction: (time, pattern, length) ->
- if length > 6
- throw 'can not use the S format with more than 6 digits'
-
- return ("000000" + Math.round(Math.pow(time.getMilliseconds() * 100.0, 6 - length)).toString()).slice(-length)
-
- timezone: (time, pattern, length) ->
- hours = ("00" + (time.getTimezoneOffset() / 60).toString()).slice(-2)
- minutes = ("00" + (time.getTimezoneOffset() % 60).toString()).slice(-2)
-
- switch length
- when 1, 2, 3
- return "-" + hours + ":" + minutes
- else
- return "UTC -" + hours + ":" + minutes
-
- timezone_generic_non_location: (time, pattern, length) ->
- throw 'not yet implemented (requires timezone translation data")'
View
52 js/lib/mustache/calendars/timespan.coffee
@@ -1,52 +0,0 @@
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-TwitterCldr.TimespanFormatter = class TimespanFormatter
- constructor: ->
- @default_type = "default"
- @tokens = `{{{tokens}}}`
- @time_in_seconds = {
- "second": 1,
- "minute": 60,
- "hour": 3600,
- "day": 86400,
- "week": 604800,
- "month": 2629743.83,
- "year": 31556926
- }
-
- format: (seconds, options = {}) ->
- options["direction"] ||= (if seconds < 0 then "ago" else "until")
- options["unit"] = this.calculate_unit(Math.abs(seconds)) if options["unit"] is null or options["unit"] is undefined
- options["type"] ||= @default_type
- options["number"] = this.calculate_time(Math.abs(seconds), options["unit"])
- number = this.calculate_time(Math.abs(seconds), options["unit"])
- options["rule"] = TwitterCldr.PluralRules.rule_for(number)
-
- strings = (token.value for token in @tokens[options["direction"]][options["unit"]][options["type"]][options["rule"]])
- strings.join("").replace(/\{[0-9]\}/, number.toString())
-
- calculate_unit: (seconds) ->
- if seconds < 30
- "second"
- else if seconds < 2670
- "minute"
- else if seconds < 86369
- "hour"
- else if seconds < 604800
- "day"
- else if seconds < 2591969
- "week"
- else if seconds < 31556926
- "month"
- else
- "year"
-
- # 0 <-> 29 secs # => seconds
- # 30 secs <-> 44 mins, 29 secs # => minutes
- # 44 mins, 30 secs <-> 23 hrs, 59 mins, 29 secs # => hours
- # 23 hrs, 59 mins, 29 secs <-> 29 days, 23 hrs, 59 mins, 29 secs # => days
- # 29 days, 23 hrs, 59 mins, 29 secs <-> 1 yr minus 1 sec # => months
- # 1 yr <-> max time or date # => years
- calculate_time: (seconds, unit) ->
- Math.round(seconds / @time_in_seconds[unit])
View
179 js/lib/mustache/numbers/numbers.coffee
@@ -1,179 +0,0 @@
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-TwitterCldr.NumberFormatter = class NumberFormatter
- constructor: ->
- @all_tokens = `{{{tokens}}}`
- @tokens = []
- @symbols = `{{{symbols}}}`
-
- @default_symbols =
- 'group': ','
- 'decimal': '.'
- 'plus_sign': '+'
- 'minus_sign': '-'
-
- format: (number, options = {}) ->
- opts = this.default_format_options_for(number)
-
- for key, val of options
- opts[key] = if options[key]? then options[key] else opts[key]
-
- [prefix, suffix, integer_format, fraction_format] = this.partition_tokens(this.get_tokens(number, opts))
- [int, fraction] = this.parse_number(number, opts)
- result = integer_format.apply(parseFloat(int), opts)
- result += fraction_format.apply(fraction, opts) if fraction
- sign = if number < 0 && prefix != "-" then @symbols.minus_sign || @default_symbols.minus_sign else ""
- "#{sign}#{prefix}#{result}#{suffix}"
-
- partition_tokens: (tokens) ->
- [tokens[0] || "",
- tokens[2] || "",
- new IntegerHelper(tokens[1], @symbols),
- new FractionHelper(tokens[1], @symbols)]
-
- parse_number: (number, options = {}) ->
- if options.precision?
- precision = options.precision
- else
- precision = this.precision_from(number)
-
- number = this.round_to(number, precision)
- Math.abs(number).toFixed(precision).split(".")
-
- precision_from: (num) ->
- parts = num.toString().split(".")
- if parts.length == 2 then parts[1].length else 0
-
- round_to: (number, precision) ->
- factor = Math.pow(10, precision)
- Math.round(number * factor) / factor
-
- get_tokens: ->
- throw "get_tokens() not implemented - use a derived class like PercentFormatter."
-
-TwitterCldr.PercentFormatter = class PercentFormatter extends NumberFormatter
- constructor: (options = {}) ->
- @default_percent_sign = "%"
- super
-
- format: (number, options = {}) ->
- super(number, options).replace('¤', @symbols.percent_sign || @default_percent_sign)
-
- default_format_options_for: (number) ->
- precision: 0
-
- get_tokens: (number, options) ->
- if number < 0 then @all_tokens.percent.negative else @all_tokens.percent.positive
-
-TwitterCldr.DecimalFormatter = class DecimalFormatter extends NumberFormatter
- format: (number, options = {}) ->
- try
- super(number, options)
- catch error
- number
-
- default_format_options_for: (number) ->
- precision: this.precision_from(number)
-
- get_tokens: (number, options = {}) ->
- if number < 0 then @all_tokens.decimal.negative else @all_tokens.decimal.positive
-
-TwitterCldr.CurrencyFormatter = class CurrencyFormatter extends NumberFormatter
- constructor: (options = {}) ->
- @default_currency_symbol = "$"
- @default_precision = 2
- super
-
- format: (number, options = {}) ->
- if options.currency
- if TwitterCldr.Currencies?
- currency = TwitterCldr.Currencies.for_code(options.currency)
- currency ||= TwitterCldr.Currencies.for_country(options.currency)
- currency ||= symbol: options.currency
- else
- currency = symbol: options.currency
- else
- currency = symbol: @default_currency_symbol
-
- super(number, options).replace('¤', currency.symbol)
-
- default_format_options_for: (number) ->
- precision = this.precision_from(number)
- if precision == 0 then precision = @default_precision
- precision: precision
-
- get_tokens: (number, options = {}) ->
- if number < 0 then @all_tokens.currency.negative else @all_tokens.currency.positive
-
-TwitterCldr.NumberFormatter.BaseHelper = class BaseHelper
- interpolate: (string, value, orientation = "right") ->
- value = value.toString()
- length = value.length
- start = if orientation == "left" then 0 else -length
- string = (("#" for i in [0...length]).join("") + string).slice(-length) if string.length < length
-
- if start < 0
- string = string[0...(start + string.length)] + value
- else
- string = string[0...start] + value + string[(length)..-1]
-
- string.replace(/#/g, "")
-
-TwitterCldr.NumberFormatter.IntegerHelper = class IntegerHelper extends BaseHelper
- constructor: (token, symbols = {}) ->
- format = token.split('.')[0]
- @format = this.prepare_format(format, symbols)
- @groups = this.parse_groups(format)
- @separator = symbols.group || ','
-
- apply: (number, options = {}) ->
- this.format_groups(this.interpolate(@format, parseInt(number)))
-
- format_groups: (string) ->
- return string if @groups.length == 0
- tokens = []
-
- cur_token = this.chop_group(string, @groups[0])
- tokens.push(cur_token)
- string = string[0...(string.length - cur_token.length)] if cur_token
-
- while string.length > @groups[@groups.length - 1]
- cur_token = this.chop_group(string, @groups[@groups.length - 1])
- tokens.push(cur_token)
- string = string[0...(string.length - cur_token.length)] if cur_token
-
- tokens.push(string)
- (token for token in tokens when token != null).reverse().join(@separator)
-
- parse_groups: (format) ->
- return [] unless index = format.lastIndexOf(',')
- rest = format[0...index]
- widths = [format.length - index - 1]
- widths.push(rest.length - rest.lastIndexOf(',') - 1) if rest.lastIndexOf(',') > -1
- widths = (width for width in widths when width != null) # compact
- widths.reverse() # uniq
- (widths[index] for index in [0...widths.length] when widths.indexOf(widths[index], index + 1) == -1).reverse()
-
- chop_group: (string, size) ->
- if string.length > size then string[-size..-1] else null
-
- prepare_format: (format, symbols) ->
- format.replace(",", "").replace("+", symbols.plus_sign).replace("-", symbols.minus_sign)
-
-TwitterCldr.NumberFormatter.FractionHelper = class FractionHelper extends BaseHelper
- constructor: (token, symbols = {}) ->
- @format = if token then token.split('.').pop() else ""
- @decimal = symbols.decimal || "."
- @precision = @format.length
-
- apply: (fraction, options = {}) ->
- precision = if options.precision? then options.precision else @precision
- if precision > 0
- @decimal + this.interpolate(this.format_for(options), fraction, "left")
- else
- ""
-
- format_for: (options) ->
- precision = if options.precision? then options.precision else @precision
- if precision then ("0" for i in [0...precision]).join("") else @format
View
14 js/lib/mustache/plurals/rules.coffee
@@ -1,14 +0,0 @@
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-TwitterCldr.PluralRules = class PluralRules
- @rules = `{{{rules}}}`
-
- @all: ->
- return @rules.keys
-
- @rule_for: (number) ->
- try
- return @rules.rule(number)
- catch error
- return "other"
View
27 js/lib/mustache/shared/currencies.coffee
@@ -1,27 +0,0 @@
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-TwitterCldr.Currencies = class Currencies
- @currencies = `{{{currencies}}}`
-
- @countries: ->
- @names ||= (country_name for country_name, data of @currencies)
-
- @currency_codes: ->
- @codes ||= (data.code for country_name, data of @currencies)
-
- @for_country: (country_name) ->
- @currencies[country_name]
-
- @for_code: (currency_code) ->
- final = null
- for country_name, data of @currencies
- if data.code == currency_code
- final =
- country: country_name
- code: data.code
- symbol: data.symbol
- currency: data.currency
- break
-
- final
View
18 js/lib/renderers/base.rb
@@ -1,18 +0,0 @@
-# encoding: UTF-8
-
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-module TwitterCldr
- module Js
- module Renderers
- class Base < Mustache
-
- def initialize(options = {})
- @locale = options[:locale]
- end
-
- end
- end
- end
-end
View
18 js/lib/renderers/bundle.rb
@@ -1,18 +0,0 @@
-# encoding: UTF-8
-
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-module TwitterCldr
- module Js
- module Renderers
- class Bundle < Mustache
- self.template_file = File.expand_path(File.join(File.dirname(__FILE__), "..", "mustache/bundle.coffee"))
-
- def version
- TwitterCldr::VERSION
- end
- end
- end
- end
-end
View
34 js/lib/renderers/calendars/datetime_renderer.rb
@@ -1,34 +0,0 @@
-# encoding: UTF-8
-
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-module TwitterCldr
- module Js
- module Renderers
- module Calendars
- class DateTimeRenderer < TwitterCldr::Js::Renderers::Base
- self.template_file = File.expand_path(File.join(File.dirname(__FILE__), "../..", "mustache/calendars/datetime.coffee"))
-
- def tokens
- tokens = {}
- { :date_time => TwitterCldr::Tokenizers::DateTimeTokenizer,
- :time => TwitterCldr::Tokenizers::TimeTokenizer,
- :date => TwitterCldr::Tokenizers::DateTokenizer }.each_pair do |name, const|
- tokenizer = const.new(:locale => @locale)
- tokens[name] = const::VALID_TYPES.inject({}) do |ret, type|
- ret[type] = tokenizer.tokens(:type => type).map(&:to_hash)
- ret
- end
- end
- tokens.to_json
- end
-
- def calendar
- TwitterCldr::Tokenizers::DateTimeTokenizer.new(:locale => @locale).calendar.to_json
- end
- end
- end
- end
- end
-end
View
39 js/lib/renderers/calendars/timespan_renderer.rb
@@ -1,39 +0,0 @@
-# encoding: UTF-8
-
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-include TwitterCldr::Tokenizers
-include TwitterCldr::Formatters
-
-module TwitterCldr
- module Js
- module Renderers
- module Calendars
-
- class TimespanRenderer < TwitterCldr::Js::Renderers::Base
- self.template_file = File.expand_path(File.join(File.dirname(__FILE__), "../..", "mustache/calendars/timespan.coffee"))
-
- def tokens
- tokenizer = TimespanTokenizer.new(:locale => @locale)
- [:ago, :until, :none].inject({}) do |final, direction|
- final[direction] = TimespanTokenizer::VALID_UNITS.inject({}) do |unit_hash, unit|
- unit_hash[unit] = tokenizer.all_types_for(unit, direction).inject({}) do |type_hash, type|
- type_hash[type] = Plurals::Rules.all_for(@locale).inject({}) do |rule_hash, rule|
- rule_hash[rule] = tokenizer.tokens(:direction => direction, :unit => unit, :rule => rule, :type => type)
- rule_hash
- end
- type_hash
- end
- unit_hash
- end
- final
- end.to_json
- end
-
- end
-
- end
- end
- end
-end
View
31 js/lib/renderers/numbers/numbers_renderer.rb
@@ -1,31 +0,0 @@
-# encoding: UTF-8
-
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-module TwitterCldr
- module Js
- module Renderers
- module Numbers
- class NumbersRenderer < TwitterCldr::Js::Renderers::Base
- self.template_file = File.expand_path(File.join(File.dirname(__FILE__), "../..", "mustache/numbers/numbers.coffee"))
-
- def tokens
- TwitterCldr::Tokenizers::NumberTokenizer::VALID_TYPES.inject({}) do |ret, type|
- tokenizer = TwitterCldr::Tokenizers::NumberTokenizer.new(:type => type, :locale => @locale)
- ret[type] = {}
- [:positive, :negative].each do |sign|
- ret[type][sign] = tokenizer.tokens(:sign => sign)
- end
- ret
- end.to_json
- end
-
- def symbols
- TwitterCldr::Tokenizers::NumberTokenizer.new(:locale => @locale).symbols.to_json
- end
- end
- end
- end
- end
-end
View
93 js/lib/renderers/plurals/rules/plural_rules_compiler.rb
@@ -1,93 +0,0 @@
-# encoding: UTF-8
-
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-require 'ruby_parser'
-
-module TwitterCldr
- module Js
- module Renderers
- module PluralRules
-
- class PluralRulesCompiler
-
- class << self
- def rule_to_js(rule_code)
- tree = RubyParser.new.parse(rule_code).to_a
- "function(n) { return #{statement_list(tree)} }"
- end
-
- protected
-
- def statement_list(tree)
- if tree.first == :block
- tree[1..-1].map { |sub_tree| send(:"_#{sub_tree.first}", sub_tree) }.join(" ")
- else
- send(:"_#{tree.first}", tree)
- end
- end
-
- def _if(tree)
- result = "(function() { if (#{statement_list(tree[1])}) { return #{statement_list(tree[2])} }"
- result << " else { return #{statement_list(tree[3])} }" if tree[3]
- "#{result} })();"
- end
-
- def _lvar(tree)
- tree.first.to_s
- end
-
- def _call(tree)
- case tree[2]
- when :==, :%, :<, :> # special operators that actually resolve to method calls
- "#{statement_list(tree[1])} #{tree[2]} #{statement_list(tree[3])}"
- when :include?
- "#{statement_list(tree[1])}.indexOf(#{statement_list(tree[3])}) >= 0"
- when :between?
- smt = "((#{statement_list(tree[1])} >= #{statement_list(tree[3][1])})"
- smt << " && (#{statement_list(tree[1])} <= #{statement_list(tree[3][2])}))"
- smt
- else
- # this should be the only case where tree[1] might be nil (i.e. the method was not called on any object)
- call = tree[1] ? "#{statement_list(tree[1])}.#{tree[2]}" : tree[2].to_s
- arglist = statement_list(tree[3])
- arglist == "" ? call : "#{call}(#{arglist})"
- end
- end
-
- def _arglist(tree)
- tree[1..-1].map { |arg| statement_list(arg) }.join(", ")
- end
-
- def _lit(tree)
- if tree[1].is_a?(Symbol) || tree[1].is_a?(String)
- %Q("#{tree[1]}")
- else
- tree[1]
- end
- end
-
- def _array(tree)
- "[#{tree[1..-1].map { |arg| statement_list(arg) }.join(", ")}]"
- end
-
- def _not(tree)
- "!(#{statement_list(tree[1])})"
- end
-
- def _and(tree)
- "#{statement_list(tree[1])} && #{statement_list(tree[2])}"
- end
-
- def _or(tree)
- "#{statement_list(tree[1])} || #{statement_list(tree[2])}"
- end
- end
-
- end
-
- end
- end
- end
-end
View
26 js/lib/renderers/plurals/rules/plural_rules_renderer.rb
@@ -1,26 +0,0 @@
-# encoding: UTF-8
-
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-module TwitterCldr
- module Js
- module Renderers
- module PluralRules
-
- class PluralRulesRenderer < TwitterCldr::Js::Renderers::Base
- self.template_file = File.expand_path(File.join(File.dirname(__FILE__), "../../..", "mustache/plurals/rules.coffee"))
-
- def rules
- ruby_str = TwitterCldr.get_locale_resource(@locale, :plurals)[@locale]
- rule_str = ruby_str.scan(/lambda\s*\{\s*\|n\|(.*?)\}/).first.first.strip
- js_str = PluralRulesCompiler.rule_to_js(rule_str)
- hash = eval(ruby_str)
- %Q({"keys": #{hash[@locale][:i18n][:plural][:keys].to_json}, "rule": #{js_str}})
- end
- end
-
- end
- end
- end
-end
View
23 js/lib/renderers/shared/currencies_renderer.rb
@@ -1,23 +0,0 @@
-# encoding: UTF-8
-
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-module TwitterCldr
- module Js
- module Renderers
- module Shared
- class CurrenciesRenderer < TwitterCldr::Js::Renderers::Base
- self.template_file = File.expand_path(File.join(File.dirname(__FILE__), "../..", "mustache/shared/currencies.coffee"))
-
- def currencies
- TwitterCldr::Shared::Currencies.countries.inject({}) do |ret, country_name|
- ret[country_name] = TwitterCldr::Shared::Currencies.for_country(country_name)
- ret
- end.to_json
- end
- end
- end
- end
- end
-end
View
87 js/lib/twitter_cldr_js.rb
@@ -1,87 +0,0 @@
-# encoding: UTF-8
-
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-require 'mustache'
-require 'uglifier'
-require 'jasmine-headless-webkit'
-require 'coffee-script'
-require 'json'
-require 'ruby_parser'
-
-require 'compiler'
-require 'renderers/bundle'
-require 'renderers/base'
-
-require 'renderers/calendars/datetime_renderer'
-require 'renderers/calendars/timespan_renderer'
-require 'renderers/numbers/numbers_renderer'
-require 'renderers/shared/currencies_renderer'
-require 'renderers/plurals/rules/plural_rules_compiler'
-require 'renderers/plurals/rules/plural_rules_renderer'
-
-module TwitterCldr
- module Js
- def self.build(options = {})
- TwitterCldr::Js::Compiler.new(options).compile do |bundle, locale|
- cur_file = (options[:file_name] || "twitter_cldr_%{locale}.js").gsub("%{locale}", locale.to_s)
-
- if options[:minify]
- ext = File.extname(cur_file)
- min_file = "#{cur_file.chomp(File.extname(cur_file))}.min#{ext}"
- File.open(File.join(build_dir, min_file), "w+") do |f|
- f.write(Uglifier.compile(bundle))
- end
- else
- File.open(File.join(build_dir, cur_file), "w+") do |f|
- f.write(bundle)
- end
- end
- end
- end
-
- def self.clean(output_dir = build_dir)
- FileUtils.rm_rf(Dir.glob(File.join(build_dir, "**")))
- end
-
- def self.build_dir
- File.join(File.dirname(File.dirname(__FILE__)), "build")
- end
-
- def self.output_dir
- @output_dir ||= build_dir
- end
-
- def self.output_dir=(new_dir)
- @output_dir = new_dir
- end
-
- def self.make(options = {})
- # clean dir, then build js
- FileUtils.mkdir_p(build_dir)
- FileUtils.rm_rf(Dir.glob(File.join(build_dir, "**")))
- build(options)
- build(options.merge({ :minify => true }))
- end
-
- def self.test
- Dir.chdir(File.dirname(__FILE__)) do
- Jasmine::Headless::Runner.run(:colors => true, :jasmine_config => File.expand_path("../spec/js/support/jasmine.yml"))
- end
- end
-
- def self.install
- FileUtils.mkdir_p(output_dir)
- Dir.glob(File.join(build_dir, "**/**")).each do |source_file|
- if File.file?(source_file)
- dest_file = File.join(output_dir, source_file.gsub(build_dir, ""))
- FileUtils.cp(source_file, dest_file)
- end
- end
- File.open(File.join(output_dir, "VERSION"), "w+") { |f| f.write(TwitterCldr::VERSION) }
- File.open(File.join(output_dir, "CLDR_VERSION"), "w+") { |f| f.write(TwitterCldr::CLDR_VERSION) }
- FileUtils.cp(File.expand_path(File.join(File.dirname(__FILE__), "../../LICENSE")), output_dir)
- end
- end
-end
View
418 js/spec/js/calendars/datetime_spec.js
@@ -1,418 +0,0 @@
-// Copyright 2012 Twitter, Inc
-// http://www.apache.org/licenses/LICENSE-2.0
-
-//= require '../../../build/twitter_cldr_en.js'
-
-describe("DateTimeFormatter", function() {
- beforeEach(function() {
- formatter = new TwitterCldr.DateTimeFormatter();
- });
-
- describe("#day", function() {
- it("test: pattern d", function() {
- expect(formatter.day(new Date(2010, 0, 1), 'd', 1)).toEqual('1');
- expect(formatter.day(new Date(2010, 0, 10), 'd', 1)).toEqual('10');
- });
-
- it("test: pattern dd", function() {
- expect(formatter.day(new Date(2010, 0, 1), 'dd', 2)).toEqual('01');
- expect(formatter.day(new Date(2010, 0, 10), 'dd', 2)).toEqual('10');
- });
- });
-
- describe("#weekday_local_stand_alone", function() {
- it("test: pattern c", function() {
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 4), 'c', 1)).toEqual('1');
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 5), 'c', 1)).toEqual('2');
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 10), 'c', 1)).toEqual('7');
- });
-
- it("test: pattern cc", function() {
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 4), 'cc', 2)).toEqual('Mon');
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 5), 'cc', 2)).toEqual('Tue');
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 10), 'cc', 2)).toEqual('Sun');
- });
-
- it("test: pattern ccc", function() {
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 4), 'ccc', 3)).toEqual('Mon');
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 5), 'ccc', 3)).toEqual('Tue');
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 10), 'ccc', 3)).toEqual('Sun');
- });
-
- it("test: pattern cccc", function() {
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 4), 'cccc', 4)).toEqual('Monday');
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 5), 'cccc', 4)).toEqual('Tuesday');
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 10), 'cccc', 4)).toEqual('Sunday');
- });
-
- it("test: pattern ccccc", function() {
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 4), 'ccccc', 5)).toEqual('M');
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 5), 'ccccc', 5)).toEqual('T');
- expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 10), 'ccccc', 5)).toEqual('S');
- });
- });
-
- describe("#weekday_local", function() {
- it("test: pattern e", function() {
- expect(formatter.weekday_local(new Date(2010, 0, 4), 'e', 1)).toEqual('1');
- expect(formatter.weekday_local(new Date(2010, 0, 5), 'e', 1)).toEqual('2');
- expect(formatter.weekday_local(new Date(2010, 0, 10), 'e', 1)).toEqual('7');
- });
-
- it("test: pattern ee", function() {
- expect(formatter.weekday_local(new Date(2010, 0, 4), 'ee', 2)).toEqual('1');
- expect(formatter.weekday_local(new Date(2010, 0, 5), 'ee', 2)).toEqual('2');
- expect(formatter.weekday_local(new Date(2010, 0, 10), 'ee', 2)).toEqual('7');
- });
-
- it("test: pattern eee", function() {
- expect(formatter.weekday_local(new Date(2010, 0, 4), 'eee', 3)).toEqual('Mon');
- expect(formatter.weekday_local(new Date(2010, 0, 5), 'eee', 3)).toEqual('Tue');
- expect(formatter.weekday_local(new Date(2010, 0, 10), 'eee', 3)).toEqual('Sun');
- });
-
- it("test: pattern eeee", function() {
- expect(formatter.weekday_local(new Date(2010, 0, 4), 'eeee', 4)).toEqual('Monday');
- expect(formatter.weekday_local(new Date(2010, 0, 5), 'eeee', 4)).toEqual('Tuesday');
- expect(formatter.weekday_local(new Date(2010, 0, 10), 'eeee', 4)).toEqual('Sunday');
- });
-
- it("test: pattern eeeee", function() {
- expect(formatter.weekday_local(new Date(2010, 0, 4), 'eeeee', 5)).toEqual('M');
- expect(formatter.weekday_local(new Date(2010, 0, 5), 'eeeee', 5)).toEqual('T');
- expect(formatter.weekday_local(new Date(2010, 0, 10), 'eeeee', 5)).toEqual('S');
- });
- });
-
- describe("#weekday", function() {
- it("test: pattern E, EE, EEE", function() {
- expect(formatter.weekday(new Date(2010, 0, 1), 'E', 1)).toEqual('Fri');
- expect(formatter.weekday(new Date(2010, 0, 1), 'EE', 2)).toEqual('Fri');
- expect(formatter.weekday(new Date(2010, 0, 1), 'EEE', 3)).toEqual('Fri');
- });
-
- it("test: pattern EEEE", function() {
- expect(formatter.weekday(new Date(2010, 0, 1), 'EEEE', 4)).toEqual('Friday');
- });
-
- it("test: pattern EEEEE", function() {
- expect(formatter.weekday(new Date(2010, 0, 1), 'EEEEE', 5)).toEqual('F');
- });
- });
-
- describe("#hour", function() {
- it("test: h", function() {
- expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'h', 1)).toEqual('12');
- expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'h', 1)).toEqual('1');
- expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'h', 1)).toEqual('11');
- expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'h', 1)).toEqual('12');
- expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'h', 1)).toEqual('11');
- });
-
- it("test: hh", function() {
- expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'hh', 2)).toEqual('12');
- expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'hh', 2)).toEqual('01');
- expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'hh', 2)).toEqual('11');
- expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'hh', 2)).toEqual('12');
- expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'hh', 2)).toEqual('11');
- });
-
- it("test: H", function() {
- expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'H', 1)).toEqual('0');
- expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'H', 1)).toEqual('1');
- expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'H', 1)).toEqual('11');
- expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'H', 1)).toEqual('12');
- expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'H', 1)).toEqual('23');
- });
-
- it("test: HH", function() {
- expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'HH', 2)).toEqual('00');
- expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'HH', 2)).toEqual('01');
- expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'HH', 2)).toEqual('11');
- expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'HH', 2)).toEqual('12');
- expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'HH', 2)).toEqual('23');
- });
-
- it("test: K", function() {
- expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'K', 1)).toEqual('0');
- expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'K', 1)).toEqual('1');
- expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'K', 1)).toEqual('11');
- expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'K', 1)).toEqual('0');
- expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'K', 1)).toEqual('11');
- });
-
- it("test: KK", function() {
- expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'KK', 2)).toEqual('00');
- expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'KK', 2)).toEqual('01');
- expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'KK', 2)).toEqual('11');
- expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'KK', 2)).toEqual('00');
- expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'KK', 2)).toEqual('11');
- });
-
- it("test: k", function() {
- expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'k', 1)).toEqual('24');
- expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'k', 1)).toEqual('1');
- expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'k', 1)).toEqual('11');
- expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'k', 1)).toEqual('12');
- expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'k', 1)).toEqual('23');
- });
-
- it("test: kk", function() {
- expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'kk', 2)).toEqual('24');
- expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'kk', 2)).toEqual('01');
- expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'kk', 2)).toEqual('11');
- expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'kk', 2)).toEqual('12');
- expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'kk', 2)).toEqual('23');
- });
- });
-
- describe("#minute", function() {
- it("test: m", function() {
- expect(formatter.minute(new Date(2000, 0, 1, 1, 1, 1), 'm', 1)).toEqual('1');
- expect(formatter.minute(new Date(2000, 0, 1, 1, 11, 1), 'm', 1)).toEqual('11');
- });
-
- it("test: mm", function() {
- expect(formatter.minute(new Date(2000, 0, 1, 1, 1, 1), 'mm', 2)).toEqual('01');
- expect(formatter.minute(new Date(2000, 0, 1, 1, 11, 1), 'mm', 2)).toEqual('11');
- });
- });
-
- // NOTE: months in JavaScript are zero-based, meaning Jan = 0, Dec = 11
- describe("#month", function() {
- it("test: pattern M", function() {
- expect(formatter.month(new Date(2010, 0, 1), 'M', 1)).toEqual('1');
- expect(formatter.month(new Date(2010, 9, 1), 'M', 1)).toEqual('10');
- });
-
- it("test: pattern MM", function() {
- expect(formatter.month(new Date(2010, 0, 1), 'MM', 2)).toEqual('01');
- expect(formatter.month(new Date(2010, 9, 1), 'MM', 2)).toEqual('10');
- });
-
- it("test: pattern MMM", function() {
- expect(formatter.month(new Date(2010, 0, 1), 'MMM', 3)).toEqual('Jan');
- expect(formatter.month(new Date(2010, 9, 1), 'MMM', 3)).toEqual('Oct');
- });
-
- it("test: pattern MMMM", function() {
- expect(formatter.month(new Date(2010, 0, 1), 'MMMM', 4)).toEqual('January');
- expect(formatter.month(new Date(2010, 9, 1), 'MMMM', 4)).toEqual('October');
- });
-
- it("test: pattern L", function() {
- expect(formatter.month(new Date(2010, 0, 1), 'L', 1)).toEqual('1');
- expect(formatter.month(new Date(2010, 9, 1), 'L', 1)).toEqual('10');
- });
-
- it("test: pattern LL", function() {
- expect(formatter.month(new Date(2010, 0, 1), 'LL', 2)).toEqual('01');
- expect(formatter.month(new Date(2010, 9, 1), 'LL', 2)).toEqual('10');
- });
- });
-
- describe("#period", function() {
- it("test: a", function() {
- expect(formatter.period(new Date(2000, 0, 1, 1, 1, 1), 'a', 1)).toEqual('a.m.');
- expect(formatter.period(new Date(2000, 0, 1, 15, 1, 1), 'a', 1)).toEqual('p.m.');
- });
- });
-
- describe("#quarter", function() {
- it("test: pattern Q", function() {
- expect(formatter.quarter(new Date(2010, 0, 1), 'Q', 1)).toEqual('1');
- expect(formatter.quarter(new Date(2010, 2, 31), 'Q', 1)).toEqual('1');
- expect(formatter.quarter(new Date(2010, 3, 1), 'Q', 1)).toEqual('2');
- expect(formatter.quarter(new Date(2010, 5, 30), 'Q', 1)).toEqual('2');
- expect(formatter.quarter(new Date(2010, 6, 1), 'Q', 1)).toEqual('3');
- expect(formatter.quarter(new Date(2010, 8, 30), 'Q', 1)).toEqual('3');
- expect(formatter.quarter(new Date(2010, 9, 1), 'Q', 1)).toEqual('4');
- expect(formatter.quarter(new Date(2010, 11, 31), 'Q', 1)).toEqual('4');
- });
-
- it("test: pattern QQ", function() {
- expect(formatter.quarter(new Date(2010, 0, 1), 'QQ', 2)).toEqual('01');
- expect(formatter.quarter(new Date(2010, 2, 31), 'QQ', 2)).toEqual('01');
- expect(formatter.quarter(new Date(2010, 3, 1), 'QQ', 2)).toEqual('02');
- expect(formatter.quarter(new Date(2010, 5, 30), 'QQ', 2)).toEqual('02');
- expect(formatter.quarter(new Date(2010, 6, 1), 'QQ', 2)).toEqual('03');
- expect(formatter.quarter(new Date(2010, 8, 30), 'QQ', 2)).toEqual('03');
- expect(formatter.quarter(new Date(2010, 9, 1), 'QQ', 2)).toEqual('04');
- expect(formatter.quarter(new Date(2010, 11, 31), 'QQ', 2)).toEqual('04');
- });
-
- it("test: pattern QQQ", function() {
- expect(formatter.quarter(new Date(2010, 0, 1), 'QQQ', 3)).toEqual('Q1');
- expect(formatter.quarter(new Date(2010, 2, 31), 'QQQ', 3)).toEqual('Q1');
- expect(formatter.quarter(new Date(2010, 3, 1), 'QQQ', 3)).toEqual('Q2');
- expect(formatter.quarter(new Date(2010, 5, 30), 'QQQ', 3)).toEqual('Q2');
- expect(formatter.quarter(new Date(2010, 6, 1), 'QQQ', 3)).toEqual('Q3');
- expect(formatter.quarter(new Date(2010, 8, 30), 'QQQ', 3)).toEqual('Q3');
- expect(formatter.quarter(new Date(2010, 9, 1), 'QQQ', 3)).toEqual('Q4');
- expect(formatter.quarter(new Date(2010, 11, 31), 'QQQ', 3)).toEqual('Q4');
- });
-
- it("test: pattern QQQQ", function() {
- expect(formatter.quarter(new Date(2010, 0, 1), 'QQQQ', 4)).toEqual('1st quarter');
- expect(formatter.quarter(new Date(2010, 2, 31), 'QQQQ', 4)).toEqual('1st quarter');
- expect(formatter.quarter(new Date(2010, 3, 1), 'QQQQ', 4)).toEqual('2nd quarter');
- expect(formatter.quarter(new Date(2010, 5, 30), 'QQQQ', 4)).toEqual('2nd quarter');
- expect(formatter.quarter(new Date(2010, 6, 1), 'QQQQ', 4)).toEqual('3rd quarter');
- expect(formatter.quarter(new Date(2010, 8, 30), 'QQQQ', 4)).toEqual('3rd quarter');
- expect(formatter.quarter(new Date(2010, 9, 1), 'QQQQ', 4)).toEqual('4th quarter');
- expect(formatter.quarter(new Date(2010, 11, 31), 'QQQQ', 4)).toEqual('4th quarter');
- });
-
- it("test: pattern q", function() {
- expect(formatter.quarter(new Date(2010, 0, 1), 'q', 1)).toEqual('1');
- expect(formatter.quarter(new Date(2010, 2, 31), 'q', 1)).toEqual('1');
- expect(formatter.quarter(new Date(2010, 3, 1), 'q', 1)).toEqual('2');
- expect(formatter.quarter(new Date(2010, 5, 30), 'q', 1)).toEqual('2');
- expect(formatter.quarter(new Date(2010, 6, 1), 'q', 1)).toEqual('3');
- expect(formatter.quarter(new Date(2010, 8, 30), 'q', 1)).toEqual('3');
- expect(formatter.quarter(new Date(2010, 9, 1), 'q', 1)).toEqual('4');
- expect(formatter.quarter(new Date(2010, 11, 31), 'q', 1)).toEqual('4');
- });
-
- it("test: pattern qq", function() {
- expect(formatter.quarter(new Date(2010, 0, 1), 'qq', 2)).toEqual('01');
- expect(formatter.quarter(new Date(2010, 2, 31), 'qq', 2)).toEqual('01');
- expect(formatter.quarter(new Date(2010, 3, 1), 'qq', 2)).toEqual('02');
- expect(formatter.quarter(new Date(2010, 5, 30), 'qq', 2)).toEqual('02');
- expect(formatter.quarter(new Date(2010, 6, 1), 'qq', 2)).toEqual('03');
- expect(formatter.quarter(new Date(2010, 8, 30), 'qq', 2)).toEqual('03');
- expect(formatter.quarter(new Date(2010, 9, 1), 'qq', 2)).toEqual('04');
- expect(formatter.quarter(new Date(2010, 11, 31), 'qq', 2)).toEqual('04');
- });
- });
-
- describe("#second", function() {
- it("test: s", function() {
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 's', 1)).toEqual('1');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 11), 's', 1)).toEqual('11');
- });
-
- it("test: ss", function() {
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'ss', 2)).toEqual('01');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 11), 'ss', 2)).toEqual('11');
- });
-
- it("test: S", function() {
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 0), 'S', 1)).toEqual('0');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'S', 1)).toEqual('1');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 18), 'S', 1)).toEqual('18');
- });
-
- it("test: SS", function() {
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 0), 'SS', 2)).toEqual('00');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'SS', 2)).toEqual('01');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 8), 'SS', 2)).toEqual('08');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 21), 'SS', 2)).toEqual('21');
- });
-
- it("test: SSS", function() {
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 0), 'SSS', 3)).toEqual('000');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'SSS', 3)).toEqual('001');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 8), 'SSS', 3)).toEqual('008');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 21), 'SSS', 3)).toEqual('021');
- });
-
- it("test: SSSS", function() {
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 0), 'SSSS', 4)).toEqual('0000');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'SSSS', 4)).toEqual('0001');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 8), 'SSSS', 4)).toEqual('0008');
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 21), 'SSSS', 4)).toEqual('0021');
- });
-
- it("test: SSSSS", function() {
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'SSSSS', 5)).toEqual('00001')
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 8), 'SSSSS', 5)).toEqual('00008')
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 21), 'SSSSS', 5)).toEqual('00021')
- });
-
- it("test: SSSSSS", function() {
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'SSSSSS', 6)).toEqual('000001')
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 8), 'SSSSSS', 6)).toEqual('000008')
- expect(formatter.second(new Date(2000, 0, 1, 1, 1, 21), 'SSSSSS', 6)).toEqual('000021')
- });
- });
-
- describe("#timezone", function() {
- beforeEach(function() {
- date = new Date(2000, 0, 1, 1, 1, 1);
- });
-
- it("test: z, zz, zzz", function() {
- expect(formatter.timezone(date, 'z', 1)).toMatch(/^(-|\+)\d{2}:\d{2}$/);
- expect(formatter.timezone(date, 'zz', 2)).toMatch(/^(-|\+)\d{2}:\d{2}$/);
- expect(formatter.timezone(date, 'zzz', 3)).toMatch(/^(-|\+)\d{2}:\d{2}$/);
- expect(formatter.timezone(date, 'zzzz', 4)).toMatch(/^UTC (-|\+)\d{2}:\d{2}$/);
- });
- });
-
- // javascript handles dates differently than Ruby does, hence why this spec expects different results than it's Ruby counterpart
- // eg. new Date(5, 0).getFullYear() == 1905
- describe("#year", function() {
- it("test: pattern y", function() {
- expect(formatter.year(new Date(5, 0, 1), 'y', 1)).toEqual('1905');
- expect(formatter.year(new Date(45, 0, 1), 'y', 1)).toEqual('1945');
- expect(formatter.year(new Date(345, 0, 1), 'y', 1)).toEqual('345');
- expect(formatter.year(new Date(2345, 0, 1), 'y', 1)).toEqual('2345');
- expect(formatter.year(new Date(12345, 0, 1), 'y', 1)).toEqual('12345');
- });
-
- it("test: pattern yy", function() {
- expect(formatter.year(new Date(5, 0, 1), 'yy', 2)).toEqual('05');
- expect(formatter.year(new Date(45, 0, 1), 'yy', 2)).toEqual('45');
- expect(formatter.year(new Date(345, 0, 1), 'yy', 2)).toEqual('45');
- expect(formatter.year(new Date(2345, 0, 1), 'yy', 2)).toEqual('45');
- expect(formatter.year(new Date(12345, 0, 1), 'yy', 2)).toEqual('45');
- });
-
- it("test: pattern yyy", function() {
- expect(formatter.year(new Date(5, 0, 1), 'yyy', 3)).toEqual('905');
- expect(formatter.year(new Date(45, 0, 1), 'yyy', 3)).toEqual('945');
- expect(formatter.year(new Date(345, 0, 1), 'yyy', 3)).toEqual('345');
- expect(formatter.year(new Date(2345, 0, 1), 'yyy', 3)).toEqual('345');
- expect(formatter.year(new Date(12345, 0, 1), 'yyy', 3)).toEqual('345');
- });
-
- it("test: pattern yyyy", function() {
- expect(formatter.year(new Date(5, 0, 1), 'yyyy', 4)).toEqual('1905');
- expect(formatter.year(new Date(45, 0, 1), 'yyyy', 4)).toEqual('1945');
- expect(formatter.year(new Date(345, 0, 1), 'yyyy', 4)).toEqual('0345');
- expect(formatter.year(new Date(2345, 0, 1), 'yyyy', 4)).toEqual('2345');
- expect(formatter.year(new Date(12345, 0, 1), 'yyyy', 4)).toEqual('2345');
- });
-
- it("test: pattern yyyyy", function() {
- expect(formatter.year(new Date(5, 0, 1), 'yyyyy', 5)).toEqual('01905');
- expect(formatter.year(new Date(45, 0, 1), 'yyyyy', 5)).toEqual('01945');
- expect(formatter.year(new Date(345, 0, 1), 'yyyyy', 5)).toEqual('00345');
- expect(formatter.year(new Date(2345, 0, 1), 'yyyyy', 5)).toEqual('02345');
- expect(formatter.year(new Date(12345, 0, 1), 'yyyyy', 5)).toEqual('12345');
- });
- });
-
- describe("#era", function() {
- it("test: pattern G", function() {
- expect(formatter.era(new Date(2012, 1, 1), 'G', 1)).toEqual("AD");
- expect(formatter.era(new Date(-1, 1, 1), 'G', 1)).toEqual("BC");
- });
-
- it("test: pattern GG", function() {
- expect(formatter.era(new Date(2012, 1, 1), 'GG', 2)).toEqual("AD");
- expect(formatter.era(new Date(-1, 1, 1), 'GG', 2)).toEqual("BC");
- });
-
- it("test: pattern GGG", function() {
- expect(formatter.era(new Date(2012, 1, 1), 'GGG', 3)).toEqual("AD");
- expect(formatter.era(new Date(-1, 1, 1), 'GGG', 3)).toEqual("BC");
- });
-
- it("test: pattern GGGG", function() {
- expect(formatter.era(new Date(2012, 1, 1), 'GGGG', 4)).toEqual("Anno Domini");
- expect(formatter.era(new Date(-1, 1, 1), 'GGGG', 4)).toEqual("Before Christ");
- });
- });
-});
View
91 js/spec/js/calendars/timespan_spec.js
@@ -1,91 +0,0 @@
-// Copyright 2012 Twitter, Inc
-// http://www.apache.org/licenses/LICENSE-2.0
-
-//= require '../../../build/twitter_cldr_en.js'
-
-describe("TimespanFormatter", function() {
- beforeEach(function() {
- formatter = new TwitterCldr.TimespanFormatter();
- });
-
- describe("#format", function() {
- it("works for a variety of units for a non-directional timespan", function() {
- expect(formatter.format(3273932, {
- unit: "year",
- direction: "none"
- })).toEqual('0 years');
- expect(formatter.format(3273932, {
- unit: "month",
- direction: "none",
- })).toEqual('1 month');
- expect(formatter.format(3273932, {
- unit: "week",
- direction: "none"
- })).toEqual('5 weeks');
- expect(formatter.format(3273932, {
- unit: "day",
- direction: "none"
- })).toEqual('38 days');
- expect(formatter.format(3273932, {
- unit: "hour",
- direction: "none"
- })).toEqual('909 hours');
- expect(formatter.format(3273932, {
- unit: "minute",
- direction: "none"
- })).toEqual('54566 minutes');
- expect(formatter.format(3273932, {
- unit: "second",
- direction: "none"
- })).toEqual('3273932 seconds');
- });
-
- it("works for a variety of units in the past", function() {
- expect(formatter.format(-3273932, {
- unit: "year"
- })).toEqual('0 years ago');
- expect(formatter.format(-3273932, {
- unit: "month"
- })).toEqual('1 month ago');
- expect(formatter.format(-3273932, {
- unit: "week"
- })).toEqual('5 weeks ago');
- expect(formatter.format(-3273932, {
- unit: "day"
- })).toEqual('38 days ago');
- expect(formatter.format(-3273932, {
- unit: "hour"
- })).toEqual('909 hours ago');
- expect(formatter.format(-3273932, {
- unit: "minute"
- })).toEqual('54566 minutes ago');
- expect(formatter.format(-3273932, {
- unit: "second"
- })).toEqual('3273932 seconds ago');
- });
-
- it("works for a variety of units in the future", function() {
- expect(formatter.format(3273932, {
- unit: "year"
- })).toEqual('In 0 years');
- expect(formatter.format(3273932, {
- unit: "month"
- })).toEqual('In 1 month');
- expect(formatter.format(3273932, {
- unit: "week"
- })).toEqual('In 5 weeks');
- expect(formatter.format(3273932, {
- unit: "day"
- })).toEqual('In 38 days');
- expect(formatter.format(3273932, {
- unit: "hour"
- })).toEqual('In 909 hours');
- expect(formatter.format(3273932, {
- unit: "minute"
- })).toEqual('In 54566 minutes');
- expect(formatter.format(3273932, {
- unit: "second"
- })).toEqual('In 3273932 seconds');
- });
- });
-});
View
34 js/spec/js/numbers/currency_spec.js
@@ -1,34 +0,0 @@
-// Copyright 2012 Twitter, Inc
-// http://www.apache.org/licenses/LICENSE-2.0
-
-//= require '../../../build/twitter_cldr_en.js'
-
-describe("CurrencyFormatter", function() {
- describe("#format", function() {
- beforeEach(function() {
- formatter = new TwitterCldr.CurrencyFormatter();
- });
-
- it("should use a dollar sign when no other currency symbol is given (and default to a precision of 2)", function() {
- expect(formatter.format(12)).toEqual("$12.00");
- });
-
- it("handles negative numbers", function() {
- // yes, the parentheses really are part of the format, don't worry about it
- expect(formatter.format(-12)).toEqual("-($12.00)");
- });
-
- it("should use the specified currency symbol when specified", function() {
- // S/. is the symbol for the Peruvian Nuevo Sol, just in case you were curious
- expect(formatter.format(12, {currency: "S/."})).toEqual("S/.12.00");
- });
-
- it("should use the currency symbol for the corresponding currency code", function() {
- expect(formatter.format(12, {currency: "PEN"})).toEqual("S/.12.00");
- });
-
- it("overrides the default precision", function() {
- expect(formatter.format(12, {precision: 3})).toEqual("$12.000");
- });
- });
-});
View
24 js/spec/js/numbers/decimal_spec.js
@@ -1,24 +0,0 @@
-// Copyright 2012 Twitter, Inc
-// http://www.apache.org/licenses/LICENSE-2.0
-
-//= require '../../../build/twitter_cldr_en.js'
-
-describe("DecimalFormatter", function() {
- beforeEach(function() {
- formatter = new TwitterCldr.DecimalFormatter();
- });
-
- describe("#format", function() {
- it("should format positive decimals correctly", function() {
- expect(formatter.format(12.1)).toEqual("12.1");
- });
-
- it("should format negative decimals correctly", function() {
- expect(formatter.format(-12.1)).toEqual("-12.1");
- });
-
- it("should respect the precision option", function() {
- expect(formatter.format(-12, {precision: 3})).toEqual("-12.000");
- });
- });
-});
View
23 js/spec/js/numbers/helpers/fraction_spec.js
@@ -1,23 +0,0 @@
-// Copyright 2012 Twitter, Inc
-// http://www.apache.org/licenses/LICENSE-2.0
-
-//= require '../../../../build/twitter_cldr_en.js'
-
-describe("FractionHelper", function() {
- describe("#apply", function() {
- it("test: formats a fraction", function() {
- var token = '###.##';
- expect(new TwitterCldr.NumberFormatter.FractionHelper(token).apply('45')).toEqual('.45');
- });
-
- it("test: pads zero digits on the right side", function() {
- var token = '###.0000#';
- expect(new TwitterCldr.NumberFormatter.FractionHelper(token).apply('45')).toEqual('.45000');
- });
-
- it("test: :precision option overrides format precision", function() {
- var token = '###.##';
- expect(new TwitterCldr.NumberFormatter.FractionHelper(token).apply('78901', {precision: 5})).toEqual('.78901');
- });
- });
-});
View
100 js/spec/js/numbers/helpers/integer_spec.js
@@ -1,100 +0,0 @@
-// Copyright 2012 Twitter, Inc
-// http://www.apache.org/licenses/LICENSE-2.0
-
-//= require '../../../../build/twitter_cldr_en.js'
-
-describe("IntegerHelper", function() {
- describe("#apply", function() {
- describe("with the ### format", function() {
- beforeEach(function() {
- token = "###";
- });
-
- it("test: interpolates a number", function() {
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token).apply(123)).toEqual('123');
- });
-
- it("test: does not include a fraction for a float", function() {
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token).apply(123.45)).toEqual('123');
- });
-
- it("test: does not round when given a float", function() {
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token).apply(123.55)).toEqual('123');
- });
-
- it("test: does not round with :precision => 1", function() {
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token).apply(123.55, {precision: 1})).toEqual('123');
- });
- });
-
- describe("with the #,## format", function() {
- beforeEach(function() {
- token = "#,##";
- });
-
- it("test: single group", function() {
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token).apply(123)).toEqual('1,23');
- });
-
- it("test: multiple groups with a primary group size", function() {
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token).apply(123456789)).toEqual('1,23,45,67,89');
- });
- });
-
- describe("with the #,##0.## format", function() {
- beforeEach(function() {
- token = "#,##0.##";
- });
-
- it("test: ignores a fraction part given in the format string", function() {
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token).apply(1234.567)).toEqual('1,234');
- });
-
- it("test: cldr example #,##0.## => 1 234", function() {
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token).apply(1234.567)).toEqual('1,234');
- });
- });
-
- describe("miscellaneous formats", function() {
- it("test: interpolates a number on the right side", function () {
- token = "0###";
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token).apply(123)).toEqual('0123');
- });
-
- it("test: strips optional digits", function() {
- token = "######";
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token).apply(123)).toEqual('123');
- });
-
- it("test: multiple groups with a primary and secondary group size", function() {
- token = "#,##,##0";
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token).apply(123456789)).toEqual('12,34,56,789');
- });
-
- it("test: does not group when no digits left of the grouping position", function() {
- token = "#,###";
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token).apply(123)).toEqual('123');
- });
-
- it("test: cldr example #,##0.### => 1 234", function() {
- token = "#,##0.###";
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token, {group: ' '}).apply(1234.567)).toEqual('1 234');
- });
-
- it("test: cldr example ###0.##### => 1234", function() {
- token = "###0.#####";
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token, {group: ' '}).apply(1234.567)).toEqual('1234');
- });
-
- it("test: cldr example ###0.0000# => 1234", function() {
- token = "###0.0000#";
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token, {group: ' '}).apply(1234.567)).toEqual('1234');
- });
-
- it("test: cldr example 00000.0000 => 01234", function() {
- token = "00000.0000";
- expect(new TwitterCldr.NumberFormatter.IntegerHelper(token, {group: ' '}).apply(1234.567)).toEqual('01234');
- });
- });
- });
-});
View
70 js/spec/js/numbers/number_spec.js
@@ -1,70 +0,0 @@
-// Copyright 2012 Twitter, Inc
-// http://www.apache.org/licenses/LICENSE-2.0
-
-//= require '../../../build/twitter_cldr_en.js'
-
-describe("NumberFormatter", function() {
- beforeEach(function() {
- formatter = new TwitterCldr.DecimalFormatter();
- });
-
- describe("#precision_from", function() {
- it("should return the correct precision", function() {
- expect(formatter.precision_from(12.123)).toEqual(3);
- });
-
- it("should return zero precision if the number isn't a decimal", function() {
- expect(formatter.precision_from(12)).toEqual(0);
- });
- });
-
- describe("#round_to", function() {
- it("should round a number to the given precision", function() {
- expect(formatter.round_to(12, 0)).toEqual(12);
- expect(formatter.round_to(12.2, 0)).toEqual(12);
- expect(formatter.round_to(12.5, 0)).toEqual(13);
- expect(formatter.round_to(12.25, 1)).toEqual(12.3);
- expect(formatter.round_to(12.25, 2)).toEqual(12.25);
- expect(formatter.round_to(12.25, 3)).toEqual(12.25);
- });
- });
-
- describe("#parse_number", function() {
- it("should round and split the given number by decimal", function() {
- expect(formatter.parse_number(12, {precision: 0})).toEqual(["12"]);
- expect(formatter.parse_number(12.2, {precision: 0})).toEqual(["12"]);
- expect(formatter.parse_number(12.5, {precision: 0})).toEqual(["13"]);
- expect(formatter.parse_number(12.25, {precision: 1})).toEqual(["12", "3"]);
- expect(formatter.parse_number(12.25, {precision: 2})).toEqual(["12", "25"]);
- expect(formatter.parse_number(12.25, {precision: 3})).toEqual(["12", "250"]);
- });
- });
-
- describe("#format", function() {
- it("should format a basic integer", function() {
- expect(formatter.format(12)).toEqual("12");
- });
-
- describe("should respect the :precision option", function() {
- it("formats with precision of 0", function() {
- expect(formatter.format(12.1, {precision: 0})).toEqual("12");
- });
-
- it("rounds and formats with precision of 1", function() {
- expect(formatter.format(12.25, {precision: 1})).toEqual("12.3");
- });
- });
-
- it("uses the length of the original decimal as the precision", function() {
- expect(formatter.format(12.8543)).toEqual("12.8543");
- });
-
- it("formats an integer larger than 999", function() {
- expect(formatter.format(1337)).toEqual("1,337");
- });
-
- it("formats a decimal larger than 999.9", function() {
- expect(formatter.format(1337.37)).toEqual("1,337.37");
- });
- });
-});
View
22 js/spec/js/numbers/percent_spec.js
@@ -1,22 +0,0 @@
-// Copyright 2012 Twitter, Inc
-// http://www.apache.org/licenses/LICENSE-2.0
-
-//= require '../../../build/twitter_cldr_en.js'
-
-describe("PercentFormatter", function() {
- beforeEach(function() {
- formatter = new TwitterCldr.PercentFormatter();
- });
-
- it("should format the number correctly", function() {
- expect(formatter.format(12)).toEqual("12%");
- });
-
- it("should format negative numbers correctly", function() {
- expect(formatter.format(-12)).toEqual("-12%");
- });
-
- it("should respect the precision option", function() {
- expect(formatter.format(-12, {precision: 3})).toEqual("-12.000%");
- });
-});
View
28 js/spec/js/plurals/plural_rules_spec.js
@@ -1,28 +0,0 @@
-// Copyright 2012 Twitter, Inc
-// http://www.apache.org/licenses/LICENSE-2.0
-
-//= require '../../../build/twitter_cldr_en.js'
-
-describe("PluralRules", function() {
- describe("#all", function() {
- it("returns an array of all English plural rules", function() {
- expect(TwitterCldr.PluralRules.all()).toEqual(["one", "other"]);
- });
- });
-
- describe("#rule_for", function() {
- it("returns 'one' for the number 1", function() {
- expect(TwitterCldr.PluralRules.rule_for(1)).toEqual("one");
- });
-
- it("returns 'other' for any number greater than 1", function() {
- for (var i = 2; i < 10; i ++) {
- expect(TwitterCldr.PluralRules.rule_for(i)).toEqual("other");
- }
- });
-
- it("returns 'other' for the number 0", function() {
- expect(TwitterCldr.PluralRules.rule_for(0)).toEqual("other");
- });
- });
-});
View
8 js/spec/js/support/jasmine.yml
@@ -1,8 +0,0 @@
-src_files:
- - "**/*.*"
-spec_files:
- - "**/*[Ss]pec.js"
-helpers:
- - helpers/**/*
-src_dir: ../../build
-spec_dir: ../
View
56 js/spec/rb/renderers/plurals/plural_rules_compiler_spec.rb
@@ -1,56 +0,0 @@
-# encoding: UTF-8
-
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
-
-include TwitterCldr::Js::Renderers::PluralRules
-
-describe PluralRulesCompiler do
- describe "#rule_to_js" do
- it "handles a single plural rule" do
- PluralRulesCompiler.rule_to_js(":other").should == 'function(n) { return "other" }'
- end
-
- it "handles a conditional plural rule (eg. English)" do
- PluralRulesCompiler.rule_to_js("n == 1 ? :one : :other").should == 'function(n) { return (function() { if (n == 1) { return "one" } else { return "other" } })(); }'
- end
-
- it "handles an include? call" do
- PluralRulesCompiler.rule_to_js("[2, 3, 4].include?(n)").should == "function(n) { return [2, 3, 4].indexOf(n) >= 0 }"
- end
-
- it "handles a between? call" do
- PluralRulesCompiler.rule_to_js("n.between?(0, 2)").should == "function(n) { return ((n >= 0) && (n <= 2)) }"
- end
-
- it "handles the modulus operator" do
- PluralRulesCompiler.rule_to_js("n % 10").should == "function(n) { return n % 10 }"
- end
-
- it "handles < and > operators" do
- PluralRulesCompiler.rule_to_js("n > 10").should == "function(n) { return n > 10 }"
- PluralRulesCompiler.rule_to_js("n < 10").should == "function(n) { return n < 10 }"
- end
-
- it "handles 'and', 'or', and 'not' operators" do
- PluralRulesCompiler.rule_to_js("n and n").should == "function(n) { return n && n }"
- PluralRulesCompiler.rule_to_js("n or n").should == "function(n) { return n || n }"
- PluralRulesCompiler.rule_to_js("not n").should == "function(n) { return !(n) }"
- end
-
- it "compounds include? and the modulus operator" do
- PluralRulesCompiler.rule_to_js("[2, 3, 4].include?(n % 10)").should == "function(n) { return [2, 3, 4].indexOf(n % 10) >= 0 }"
- end
-
- it "compounds include?, modulus, and an if statement" do
- PluralRulesCompiler.rule_to_js("[2, 3, 4].include?(n % 10) ? :one : :other").should == 'function(n) { return (function() { if ([2, 3, 4].indexOf(n % 10) >= 0) { return "one" } else { return "other" } })(); }'
- end
-
- it "chains two if statements (eg. Polish)" do
- ruby_string = "n == 1 ? :one : [2, 3, 4].include?(n % 10) && ![12