Changeset 98

Show
Ignore:
Timestamp:
01/29/08 23:01:39 (8 months ago)
Author:
deveiant
Message:

Started update of specs and build system

Location:
trunk
Files:
9 added
3 modified
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/Linguistics.tmproj

    r95 r98  
    11<?xml version="1.0" encoding="UTF-8"?> 
    2 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
     2<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
    33<plist version="1.0"> 
    44<dict> 
    55    <key>currentDocument</key> 
    6     <string>lib/linguistics.rb</string> 
     6    <string>tests/en/inflect.tests.rb</string> 
    77    <key>documents</key> 
    88    <array> 
     
    1313            <string>Linguistics</string> 
    1414            <key>regexFolderFilter</key> 
    15             <string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string> 
     15            <string>!.*/(\.(svn|DS_Store)|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string> 
    1616            <key>sourceDirectory</key> 
    1717            <string></string> 
     
    2222    <key>metaData</key> 
    2323    <dict> 
    24         <key>.irbrc</key> 
    25         <dict> 
    26             <key>caret</key> 
    27             <dict> 
    28                 <key>column</key> 
    29                 <integer>24</integer> 
    30                 <key>line</key> 
    31                 <integer>30</integer> 
     24        <key>README</key> 
     25        <dict> 
     26            <key>caret</key> 
     27            <dict> 
     28                <key>column</key> 
     29                <integer>44</integer> 
     30                <key>line</key> 
     31                <integer>34</integer> 
    3232            </dict> 
    3333            <key>columnSelection</key> 
     
    3636            <integer>0</integer> 
    3737            <key>firstVisibleLine</key> 
    38             <integer>0</integer> 
    39             <key>selectFrom</key> 
    40             <dict> 
    41                 <key>column</key> 
    42                 <integer>45</integer> 
    43                 <key>line</key> 
    44                 <integer>30</integer> 
    45             </dict> 
    46             <key>selectTo</key> 
    47             <dict> 
    48                 <key>column</key> 
    49                 <integer>24</integer> 
    50                 <key>line</key> 
    51                 <integer>30</integer> 
    52             </dict> 
    53         </dict> 
    54         <key>README</key> 
    55         <dict> 
    56             <key>caret</key> 
    57             <dict> 
    58                 <key>column</key> 
    59                 <integer>44</integer> 
    60                 <key>line</key> 
    61                 <integer>34</integer> 
    62             </dict> 
    63             <key>columnSelection</key> 
    64             <false/> 
    65             <key>firstVisibleColumn</key> 
    66             <integer>0</integer> 
    67             <key>firstVisibleLine</key> 
    6838            <integer>23</integer> 
    6939            <key>selectFrom</key> 
     
    11080            <integer>0</integer> 
    11181        </dict> 
    112         <key>lib/linguistics.rb</key> 
    113         <dict> 
    114             <key>caret</key> 
    115             <dict> 
    116                 <key>column</key> 
    117                 <integer>0</integer> 
    118                 <key>line</key> 
    119                 <integer>272</integer> 
    120             </dict> 
    121             <key>firstVisibleColumn</key> 
    122             <integer>0</integer> 
    123             <key>firstVisibleLine</key> 
    124             <integer>246</integer> 
    125         </dict> 
    126         <key>lib/linguistics/en.rb</key> 
    127         <dict> 
    128             <key>caret</key> 
    129             <dict> 
    130                 <key>column</key> 
    131                 <integer>0</integer> 
    132                 <key>line</key> 
    133                 <integer>0</integer> 
    134             </dict> 
    135             <key>firstVisibleColumn</key> 
    136             <integer>0</integer> 
    137             <key>firstVisibleLine</key> 
    138             <integer>23</integer> 
    139         </dict> 
    14082        <key>lib/linguistics/en/linkparser.rb</key> 
    14183        <dict> 
     
    15193            <key>firstVisibleLine</key> 
    15294            <integer>0</integer> 
     95        </dict> 
     96        <key>tests/en/inflect.tests.rb</key> 
     97        <dict> 
     98            <key>caret</key> 
     99            <dict> 
     100                <key>column</key> 
     101                <integer>20</integer> 
     102                <key>line</key> 
     103                <integer>372</integer> 
     104            </dict> 
     105            <key>firstVisibleColumn</key> 
     106            <integer>0</integer> 
     107            <key>firstVisibleLine</key> 
     108            <integer>276</integer> 
    153109        </dict> 
    154110        <key>tests/en/linkparser.tests.rb</key> 
     
    183139    <key>openDocuments</key> 
    184140    <array> 
    185         <string>tests/en/lprintf.tests.rb</string> 
    186         <string>lib/linguistics/en.rb</string> 
    187         <string>README</string> 
    188         <string>experiments/farmobjs.rb</string> 
    189         <string>.irbrc</string> 
    190         <string>tests/en/linkparser.tests.rb</string> 
    191         <string>examples/generalize_sentence.rb</string> 
    192         <string>lib/linguistics.rb</string> 
    193         <string>lib/linguistics/en/linkparser.rb</string> 
     141        <string>tests/en/inflect.tests.rb</string> 
    194142    </array> 
    195143    <key>showFileHierarchyDrawer</key> 
    196144    <true/> 
     145    <key>treeState</key> 
     146    <dict> 
     147        <key>Linguistics</key> 
     148        <dict> 
     149            <key>isExpanded</key> 
     150            <true/> 
     151            <key>subItems</key> 
     152            <dict> 
     153                <key>lib</key> 
     154                <dict> 
     155                    <key>isExpanded</key> 
     156                    <true/> 
     157                    <key>subItems</key> 
     158                    <dict> 
     159                        <key>linguistics</key> 
     160                        <dict> 
     161                            <key>isExpanded</key> 
     162                            <true/> 
     163                            <key>subItems</key> 
     164                            <dict> 
     165                                <key>en</key> 
     166                                <dict> 
     167                                    <key>isExpanded</key> 
     168                                    <true/> 
     169                                    <key>subItems</key> 
     170                                    <dict/> 
     171                                </dict> 
     172                            </dict> 
     173                        </dict> 
     174                    </dict> 
     175                </dict> 
     176                <key>spec</key> 
     177                <dict> 
     178                    <key>isExpanded</key> 
     179                    <true/> 
     180                    <key>subItems</key> 
     181                    <dict> 
     182                        <key>linguistics</key> 
     183                        <dict> 
     184                            <key>isExpanded</key> 
     185                            <true/> 
     186                            <key>subItems</key> 
     187                            <dict/> 
     188                        </dict> 
     189                    </dict> 
     190                </dict> 
     191                <key>tests</key> 
     192                <dict> 
     193                    <key>isExpanded</key> 
     194                    <true/> 
     195                    <key>subItems</key> 
     196                    <dict> 
     197                        <key>en</key> 
     198                        <dict> 
     199                            <key>isExpanded</key> 
     200                            <true/> 
     201                            <key>subItems</key> 
     202                            <dict/> 
     203                        </dict> 
     204                    </dict> 
     205                </dict> 
     206            </dict> 
     207        </dict> 
     208    </dict> 
    197209    <key>windowFrame</key> 
    198     <string>{{302, 28}, {837, 1000}}</string> 
     210    <string>{{302, 63}, {837, 965}}</string> 
    199211</dict> 
    200212</plist> 
  • trunk/lib/linguistics.rb

    r95 r98  
    4040    # Subversion ID 
    4141    SVNid = %q$Id$ 
     42 
     43    # Release version 
     44    VERSION = '1.0.6' 
    4245 
    4346    # Language module implementors should do something like: 
  • trunk/lib/linguistics/iso639.rb

    r39 r98  
    1919    # Read through the source for this file, capturing everything 
    2020    # between __END__ and __END_DATA__ tokens. 
    21     inDataSection = false 
     21    in_data_section = false 
    2222    File::readlines( __FILE__ ).each {|line| 
    2323        case line 
    2424        when /^__END_DATA__$/ 
    25             inDataSection = false 
     25            in_data_section = false 
    2626            false 
    2727             
    2828        when /^__END__$/ 
    29             inDataSection = true 
     29            in_data_section = true 
    3030            false 
    3131             
    3232        else 
    33             if inDataSection 
     33            if in_data_section 
    3434                codes, desc = line[0,15].split(%r{/|\s+}), line[15...-1] 
    3535                codes.delete_if {|code| code.empty?} 
  • trunk/spec/linguistics/en_spec.rb

    r95 r98  
    1 #!/usr/bin/ruby -w 
    2 # 
    3 # Unit test for English conjunctions  
    4 # $Id: conjunction.tests.rb,v 1.2 2003/09/11 05:03:12 deveiant Exp $ 
    5 # 
    6 # Copyright (c) 2003, 2005 The FaerieMUD Consortium. 
    7 #  
    8  
    9 unless defined? Linguistics::TestCase 
    10     testsdir = File::dirname( File::dirname(File::expand_path( __FILE__ )) ) 
    11     $LOAD_PATH.unshift testsdir unless $LOAD_PATH.include?( testsdir ) 
    12  
    13     require 'lingtestcase' 
     1#!/usr/bin/env spec -cfs 
     2 
     3BEGIN { 
     4    require 'pathname' 
     5    basedir = Pathname.new( __FILE__ ).dirname.parent.parent 
     6 
     7    libdir = basedir + "lib" 
     8 
     9    $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir ) 
     10} 
     11 
     12begin 
     13    require 'spec/runner' 
     14    require 'linguistics' 
     15    require 'linguistics/en' 
     16rescue LoadError 
     17    unless Object.const_defined?( :Gem ) 
     18        require 'rubygems' 
     19        retry 
     20    end 
     21    raise 
    1422end 
    1523 
    1624 
    17 ### This test suite tests the stage1 (static) parser and the metagrammar it 
    18 ### parses in which the actual parser-generator's behaviour is defined. 
    19 class EnglishConjunctionsTestCase < Linguistics::TestCase 
    20  
    21     Linguistics::use( :en, :installProxy => true ) 
    22     include Linguistics::EN 
     25describe Linguistics::EN do 
     26 
     27    before( :all ) do 
     28        Linguistics::use( :en ) 
     29        include Linguistics::EN 
     30    end 
     31 
     32 
     33    describe "conjunctions with an Array of a single element" do 
     34 
     35        before( :each ) do 
     36            @array = ['cat'] 
     37        end 
     38 
     39        it "results in a phrase with indefinite article" do 
     40            @array.en.conjunction.should == "a cat" 
     41        end 
     42         
     43    end 
     44 
     45 
     46    describe "conjunction with an Array of two different words" do 
     47 
     48        before( :each ) do 
     49            @array = ['cat', 'dog'] 
     50        end 
     51 
     52        it "results in a phrase joined with 'and' with default options" do 
     53            @array.en.conjunction.should == "a cat and a dog" 
     54        end 
     55         
     56        it "results in a phrase joined with 'plus' if 'plus' is set as the conjunctive" do 
     57            @array.en.conjunction(:conjunctive => 'plus').should == "a cat plus a dog" 
     58        end 
     59         
     60        it "results in a phrase joined with a space if an empty string is set as the conjunctive" do 
     61            @array.en.conjunction(:conjunctive => '').should == "a cat a dog" 
     62        end 
     63         
     64    end 
     65 
     66 
     67    describe "conjunction with an Array of two words that differ only in case" do 
     68 
     69        before( :each ) do 
     70            @array = ['cat', 'Cat'] 
     71        end 
     72 
     73        it "combines them into their downcased equivalents with default options" do 
     74            @array.en.conjunction.should == "two cats" 
     75        end 
     76         
     77        it "lists them separately if :combine is set to false" do 
     78            @array.en.conjunction(:combine => false).should == "a cat and a Cat" 
     79        end 
     80         
     81        it "doesn't combine them if :casefold is turned off" do 
     82            @array.en.conjunction(:casefold => false).should == "a cat and a Cat" 
     83        end 
     84         
     85        it "combines and lists them with a non-specific count if :generalize is set" do 
     86            @array.en.conjunction(:generalize => true).should == "several cats" 
     87        end 
     88         
     89    end 
     90 
     91 
     92    describe "conjunction with an Array of many (more than two) words of varying cases" do 
     93 
     94        before( :each ) do 
     95            @array = %w{cat dog fox dog chicken chicken Fox chicken goose Dog goose} 
     96        end 
     97 
     98        it "combines them into their downcased equivalents and lists them in order of amount " + 
     99           "with default options" do 
     100            @array.en.conjunction.should ==  
     101                'three dogs, three chickens, two foxes, two geese, and a cat' 
     102        end 
     103         
     104        it "lists them separately if :combine is set to false" do 
     105            @array.en.conjunction(:combine => false).should ==  
     106                'a cat, a dog, a fox, a dog, a chicken, a chicken, a Fox, a '\ 
     107                'chicken, a goose, a Dog, and a goose' 
     108        end 
     109         
     110        it "doesn't combine the differently-cased ones if :casefold is turned off" do 
     111            @array.en.conjunction(:casefold => false).should ==  
     112                'three chickens, two dogs, two geese, a cat, a fox, a Fox, '\ 
     113                'and a Dog' 
     114        end 
     115         
     116        it "combines and lists them with a non-specific count if :generalize is set" do 
     117            @array.en.conjunction(:generalize => true).should ==  
     118                'several dogs, several chickens, several foxes, several '\ 
     119                'geese, and a cat' 
     120        end 
     121         
     122    end 
    23123     
    24     Tests = { 
    25         # Test name     => { 
    26         #   target => { 
    27         #       {<options>} => <expected output> 
    28         #   }, 
    29         :singleWord => { 
    30             ['cat'] => { 
    31                 {} => %{a cat} 
    32             }, 
    33         }, 
    34  
    35         :twoWord => { 
    36             %w{cat dog} => { 
    37                 {} => 'a cat and a dog', 
    38                 {:conjunctive => 'plus'} => 'a cat plus a dog', 
    39                 {:conjunctive => ''} => 'a cat a dog', 
    40             }, 
    41             %w{cat Cat} => { 
    42                 {} => %{two cats}, 
    43                 {:combine => false} => 'a cat and a Cat', 
    44                 {:casefold => false} => 'a cat and a Cat', 
    45                 {:generalize => true} => 'several cats', 
    46             }, 
    47         }, 
    48  
    49         :manyWord => { 
    50             %w{cat dog fox dog chicken chicken Fox chicken goose Dog goose} => { 
    51                 {} => 'three dogs, three chickens, two foxes, two geese, and a cat', 
    52                 {:combine => false} =>  
    53                     'a cat, a dog, a fox, a dog, a chicken, a chicken, a Fox, a '\ 
    54                     'chicken, a goose, a Dog, and a goose', 
    55                 {:casefold => false} =>  
    56                     'three chickens, two dogs, two geese, a cat, a fox, a Fox, '\ 
    57                     'and a Dog', 
    58                 {:generalize => true} =>  
    59                     'several dogs, several chickens, several foxes, several '\ 
    60                     'geese, and a cat', 
     124 
     125    describe "conjunction with an object-transform block" do 
     126 
     127        it "doesn't still have #6: #conjunction doesn't invoke supplied block under some conditions" 
     128        before( :each ) do 
     129            # Create a new class, as we need to guarantee that this will be the 
     130            # first #conjunction call to it. 
     131            @collection = Class::new { 
     132                include Enumerable, Linguistics 
     133                def initialize( *ary ) 
     134                    @ary = ary.flatten 
     135                end 
     136 
     137                # Delegate #each to the contained Array 
     138                def each( &block ) 
     139                    @ary.each( &block ) 
     140                end 
    61141            } 
    62         }, 
    63     } 
    64  
    65     # Auto-generate tests for the dataset 
    66     Tests.each_with_index {|test,i| 
    67         name = test[0] 
    68         methname = "test_%03d_%s" % 
    69             [ i + 50, name ] 
    70         define_method( methname ) { 
    71             printTestHeader "Conjunction: #{name}" 
    72             Tests[name].each {|target, tests| 
    73                 rval = nil 
    74                 tests.each {|opts, output| 
    75                     op = "conjunction of %s with options=%s" % 
    76                         [ target.inspect, opts.inspect ] 
    77  
    78                     # Method interface 
    79                     assert_nothing_raised( op ) { 
    80                         rval = target.en.conjunction( opts ) 
    81                     } 
    82                     assert_equal output, rval, op 
    83  
    84                     # Function interface 
    85                     assert_nothing_raised( op ) { 
    86                         rval = conjunction( target, opts ) 
    87                     } 
    88                     assert_equal output, rval, op 
    89                 } 
    90             } 
    91         } 
    92     } 
    93      
    94     ### Overridden initializer: auto-generated test methods have an arity of 1 
    95     ### even though they don't require an argument (as of the current Ruby CVS), 
    96     ### and the default initializer throws an :invalid_test for methods with 
    97     ### arity != 0. 
    98     def initialize( test_method_name ) 
    99         if !respond_to?( test_method_name ) 
    100             throw :invalid_test 
    101         end 
    102         @method_name = test_method_name 
    103         @test_passed = true 
    104     end 
    105  
    106  
    107     ################################################################# 
    108     ### T E S T S 
    109     ################################################################# 
    110  
    111     Items = %w{cow chicken blancmange cyclist} 
    112  
    113     # Test for defect #6 
    114     def test_conjunction_should_use_supplied_block_for_object_transform_on_first_invocation 
    115         rval = nil 
    116  
    117         # Create a new class, as we need to guarantee that this will be the 
    118         # first #conjunction call to it. 
    119         collection = Class::new { 
    120             include Enumerable, Linguistics 
    121             def initialize( *ary ) 
    122                 @ary = ary.flatten 
    123             end 
    124  
    125             # Delegate #each to the contained Array 
    126             def each( &block ) 
    127                 @ary.each( &block ) 
    128             end 
    129         } 
    130  
    131         obj = collection.new( 'foo', 'bar', 'baz' ) 
    132  
    133         assert_nothing_raised do 
    134             rval = obj.en.conjunction {|word| "%d-letter word" % word.length } 
    135         end 
    136     end 
     142 
     143            @obj = @collection.new( 'foo', 'bar', 'baz', 'tree', 'node', 'sonogram' ) 
     144        end 
     145 
     146        it "uses supplied block for object transform on first invocation" do 
     147            @obj.en.conjunction {|word| "%s-letter word" % word.length.en.numwords }.should == 
     148                "three three-letter words, two four-letter words, and an eight-letter word" 
     149        end 
     150    end 
     151 
    137152 
    138153 
  • trunk/spec/linguistics_spec.rb

    r95 r98  
    1 #!/usr/bin/ruby -w 
    2 # 
    3 # Unit test for the 'use' function of the Linguistics module. 
    4 # $Id$ 
    5 # 
    6 # Copyright (c) 2003 The FaerieMUD Consortium. 
    7 #  
     1#!/usr/bin/env spec -cfs 
    82 
    9 unless defined? Linguistics::TestCase 
    10     testsdir = File::dirname( File::expand_path( __FILE__ ) ) 
    11     $LOAD_PATH.unshift testsdir unless $LOAD_PATH.include?( testsdir ) 
     3BEGIN { 
     4    require 'pathname' 
     5    basedir = Pathname.new( __FILE__ ).dirname.parent 
    126 
    13     require 'lingtestcase' 
     7    libdir = basedir + "lib" 
     8 
     9    $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir ) 
     10} 
     11 
     12begin 
     13    require 'spec/runner' 
     14    require 'linguistics' 
     15rescue LoadError 
     16    unless Object.const_defined?( :Gem ) 
     17        require 'rubygems' 
     18        retry 
     19    end 
     20    raise 
    1421end 
    1522 
    1623 
    17 ### This test suite tests the language-installation function of the Linguistics 
    18 ### module. 
    19 module Linguistics 
    20 class UseTestCase < Linguistics::TestCase 
    21  
    22     LanguageCodes = [ :en, :EN, 'en', 'EN', 'En', 'eN' ] 
    23     BogusLanguageCodes = [ :zz, :ry, :qi ] 
    24     MissingLanguageCodes = [ :ja, :fr, :es ] 
     24describe Linguistics do 
    2525 
    2626    TestArray = %w{stone stick hammer stone lantern} 
     
    2828    TestNumber = 5 
    2929 
    30     def test_00_UseEnglish 
    31         printTestHeader "Linguistics: Use <language>" 
     30    before( :all ) do 
     31        Linguistics.use( :en ) 
     32    end 
    3233 
    33         # Test the only (currently) valid codes 
    34         LanguageCodes.each do |code| 
    35             assert_nothing_raised { 
    36                 Linguistics::use( code ) 
    37             } 
     34 
     35    it "loads a language's linguistic functions via variants of its ISO639 code" do 
     36 
     37        [:en, :EN, 'en', 'EN', 'En', 'eN'].each do |code| 
     38            res = Linguistics.use( code ) 
     39            res.should have(3).members 
     40            res.should include(Array) 
     41            res.should include(String) 
     42            res.should include(Numeric) 
    3843        end 
     44    end 
    3945 
    40         # Test bogus codes 
    41         BogusLanguageCodes.each do |code| 
    42             assert_raises( RuntimeError ) { 
    43                 Linguistics::use( code ) 
    44             } 
     46 
     47    it "raises an error when a language that doesn't exist is requested" do 
     48        [ :zz, :ry, :qi ].each do |code| 
     49            lambda {  
     50                Linguistics.use( code ) 
     51              }.should raise_error( RuntimeError, /unknown language code/i ) 
    4552        end 
    46  
    47         # Test valid, but missing languages (might fail for implementors of new 
    48         # languages). 
    49         MissingLanguageCodes.each do |code| 
    50             assert_raises( LoadError ) { 
    51                 Linguistics::use( code ) 
    52             } 
     53    end 
     54     
     55     
     56    it "raises an error for valid languages that don't have any linguistic functions to load" do 
     57        [ :ja, :fr, :es ].each do |code| 
     58            lambda { 
     59                Linguistics.use( code )