Browse files

initial failing reference implementation in ruby

  • Loading branch information...
1 parent 538b11d commit 97f36278c47417c4590c9ea90294410ac4973dc6 @rcarver rcarver committed May 17, 2010
View
43 lib/fontvariationdescription.rb
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/fontvariationdescription/compactor'
+require File.dirname(__FILE__) + '/fontvariationdescription/expander'
+
+module FontVariationDescription
+ VERSION = '0.9.0'
+
+ PROPERTIES = [
+ 'font-style',
+ 'font-weight'
+ ]
+
+ VALUES = {
+ 'font-style' => [
+ ['n', 'normal'],
+ ['i', 'italic'],
+ ['o', 'oblique']
+ ],
+ 'font-weight' => [
+ ['1', '100'],
+ ['2', '200'],
+ ['3', '300'],
+ ['4', '400'],
+ ['5', '500'],
+ ['6', '600'],
+ ['7', '700'],
+ ['8', '800'],
+ ['9', '900'],
+ ['4', 'normal'],
+ ['7', 'bold']
+ ]
+ }
+
+ def self.compact(input)
+ @compacter ||= Compacter.new
+ @compacter.parse(input)
+ end
+
+ def self.expand(input)
+ @expander ||= Expander.new
+ @expander.parse(input)
+ end
+
+end
View
13 lib/fontvariationdescription/compactor.rb
@@ -0,0 +1,13 @@
+module FontVariationDescription
+ class Compactor
+
+ def initialize(properties=PROPERTIES, values=VALUES)
+ @properties = properties
+ @values = values
+ end
+
+ def parse(input)
+ end
+
+ end
+end
View
12 lib/fontvariationdescription/expander.rb
@@ -0,0 +1,12 @@
+module FontVariationDescription
+ class Expander
+
+ def initialize(properties=PROPERTIES, values=VALUES)
+ @properties = properties
+ @values = values
+ end
+
+ def parse(input)
+ end
+ end
+end
View
23 test/compactor_test.rb
@@ -0,0 +1,23 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+class CompatorTest < Test::Unit::TestCase
+
+ def setup
+ @compactor = FontVariationDescription::Compactor.new
+ end
+
+ Data = YAML.load_file(File.dirname(__FILE__) + "/../expand.yml")
+
+ Data['tests'].each_with_index do |test, index|
+ description = test['description']
+ fvd = test['fvd']
+ fontface = test['fontface']
+
+ define_method "test_#{index}_#{description.gsub(/\W/, '')}" do
+ expected = fvd
+ actual = @compactor.parse(fontface)
+ assert_equal actual, expected, description
+ end
+ end
+
+end
View
23 test/expander_test.rb
@@ -0,0 +1,23 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+class ExpanderTest < Test::Unit::TestCase
+
+ def setup
+ @expander = FontVariationDescription::Expander.new
+ end
+
+ Data = YAML.load_file(File.dirname(__FILE__) + "/../expand.yml")
+
+ Data['tests'].each_with_index do |test, index|
+ description = test['description']
+ fvd = test['fvd']
+ fontface = test['fontface']
+
+ define_method "test_#{index}_#{description.gsub(/\W/, '')}" do
+ expected = fontface
+ actual = @expander.parse(fvd)
+ assert_equal actual, expected, description
+ end
+ end
+
+end
View
5 test/test_helper.rb
@@ -0,0 +1,5 @@
+require 'test/unit'
+require 'yaml'
+
+require File.dirname(__FILE__) + '/../lib/fontvariationdescription'
+

0 comments on commit 97f3627

Please sign in to comment.