New test for using Ruby keywords as method names.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8764 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
961d9a4e08
commit
b3fd2c21f9
3 changed files with 215 additions and 1 deletions
|
|
@ -17,7 +17,8 @@ CPP_TEST_CASES = \
|
|||
primitive_types \
|
||||
li_cdata \
|
||||
li_cstring \
|
||||
naming
|
||||
naming \
|
||||
keywords
|
||||
|
||||
C_TEST_CASES += \
|
||||
li_cdata \
|
||||
|
|
|
|||
65
Examples/test-suite/ruby/keywords.i
Normal file
65
Examples/test-suite/ruby/keywords.i
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
%module keywords
|
||||
|
||||
// fix up conflicts with C++ keywords
|
||||
%rename("and") Keywords::and_;
|
||||
%rename("break") Keywords::break_;
|
||||
%rename("case") Keywords::case_;
|
||||
%rename("class") Keywords::class_;
|
||||
%rename("defined?") Keywords::defined_;
|
||||
%rename("do") Keywords::do_;
|
||||
%rename("else") Keywords::else_;
|
||||
%rename("false") Keywords::false_;
|
||||
%rename("for") Keywords::for_;
|
||||
%rename("if") Keywords::if_;
|
||||
%rename("not") Keywords::not_;
|
||||
%rename("return") Keywords::return_;
|
||||
%rename("or") Keywords::or_;
|
||||
%rename("true") Keywords::true_;
|
||||
%rename("while") Keywords::while_;
|
||||
|
||||
|
||||
%inline %{
|
||||
|
||||
class Keywords {
|
||||
public:
|
||||
Keywords() {}
|
||||
|
||||
char* alias() { return "alias"; }
|
||||
char* and_() { return "and"; }
|
||||
char* begin() { return "begin"; }
|
||||
char* break_() { return "break"; }
|
||||
char* case_() { return "case"; }
|
||||
char* class_() { return "class"; }
|
||||
char* def() { return "def"; }
|
||||
char* defined_() { return "defined?"; }
|
||||
char* do_() { return "do"; }
|
||||
char* else_() { return "else"; }
|
||||
char* elsif() { return "elsif"; }
|
||||
char* end() { return "end"; }
|
||||
char* ensure() { return "ensure"; }
|
||||
char* false_() { return "false"; }
|
||||
char* for_() { return "for"; }
|
||||
char* if_() { return "if"; }
|
||||
char* in() { return "in"; }
|
||||
char* module() { return "module"; }
|
||||
char* next() { return "next"; }
|
||||
char* nil() { return "nil"; }
|
||||
char* not_() { return "not"; }
|
||||
char* or_() { return "or"; }
|
||||
char* redo() { return "redo"; }
|
||||
char* rescue() { return "rescue"; }
|
||||
char* retry() { return "retry"; }
|
||||
char* return_() { return "return"; }
|
||||
char* self() { return "self"; }
|
||||
char* super() { return "super"; }
|
||||
char* then() { return "then"; }
|
||||
char* true_() { return "true"; }
|
||||
char* undef() { return "undef"; }
|
||||
char* under() { return "under"; }
|
||||
char* unless() { return "unless"; }
|
||||
char* until() { return "until"; }
|
||||
char* when() { return "when"; }
|
||||
char* while_() { return "while"; }
|
||||
char* yield() { return "yield"; }
|
||||
};
|
||||
%}
|
||||
148
Examples/test-suite/ruby/keywords_runme.rb
Normal file
148
Examples/test-suite/ruby/keywords_runme.rb
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
require 'keywords'
|
||||
|
||||
kw = Keywords::Keywords.new
|
||||
|
||||
if kw.alias != 'alias' then
|
||||
raise RuntimeError, 'Keyword method did not work: alias'
|
||||
end
|
||||
|
||||
if kw.and != 'and' then
|
||||
raise RuntimeError, 'Keyword method did not work: and'
|
||||
end
|
||||
|
||||
if kw.begin != 'begin' then
|
||||
raise RuntimeError, 'Keyword method did not work: begin'
|
||||
end
|
||||
|
||||
if kw.break != 'break' then
|
||||
raise RuntimeError, 'Keyword method did not work: break'
|
||||
end
|
||||
|
||||
if kw.case != 'case' then
|
||||
raise RuntimeError, 'Keyword method did not work: case'
|
||||
end
|
||||
|
||||
if kw.class != 'class' then
|
||||
raise RuntimeError, 'Keyword method did not work: class'
|
||||
end
|
||||
|
||||
if kw.def != 'def' then
|
||||
raise RuntimeError, 'Keyword method did not work: def'
|
||||
end
|
||||
|
||||
if kw.defined? != 'defined?' then
|
||||
raise RuntimeError, 'Keyword method did not work: defined?'
|
||||
end
|
||||
|
||||
if kw.do != 'do' then
|
||||
raise RuntimeError, 'Keyword method did not work: do'
|
||||
end
|
||||
|
||||
if kw.else != 'else' then
|
||||
raise RuntimeError, 'Keyword method did not work: else'
|
||||
end
|
||||
|
||||
if kw.elsif != 'elsif' then
|
||||
raise RuntimeError, 'Keyword method did not work: elsif'
|
||||
end
|
||||
|
||||
if kw.end != 'end' then
|
||||
raise RuntimeError, 'Keyword method did not work: end'
|
||||
end
|
||||
|
||||
if kw.ensure != 'ensure' then
|
||||
raise RuntimeError, 'Keyword method did not work: ensure'
|
||||
end
|
||||
|
||||
if kw.false != 'false' then
|
||||
raise RuntimeError, 'Keyword method did not work: false'
|
||||
end
|
||||
|
||||
if kw.for != 'for' then
|
||||
raise RuntimeError, 'Keyword method did not work: for'
|
||||
end
|
||||
|
||||
if kw.if != 'if' then
|
||||
raise RuntimeError, 'Keyword method did not work: if'
|
||||
end
|
||||
|
||||
if kw.in != 'in' then
|
||||
raise RuntimeError, 'Keyword method did not work: in'
|
||||
end
|
||||
|
||||
if kw.module != 'module' then
|
||||
raise RuntimeError, 'Keyword method did not work: module'
|
||||
end
|
||||
|
||||
if kw.next != 'next' then
|
||||
raise RuntimeError, 'Keyword method did not work: next'
|
||||
end
|
||||
|
||||
if kw.nil != 'nil' then
|
||||
raise RuntimeError, 'Keyword method did not work: nil'
|
||||
end
|
||||
|
||||
if kw.not != 'not' then
|
||||
raise RuntimeError, 'Keyword method did not work: not'
|
||||
end
|
||||
|
||||
if kw.or != 'or' then
|
||||
raise RuntimeError, 'Keyword method did not work: or'
|
||||
end
|
||||
|
||||
if kw.redo != 'redo' then
|
||||
raise RuntimeError, 'Keyword method did not work: redo'
|
||||
end
|
||||
|
||||
if kw.rescue != 'rescue' then
|
||||
raise RuntimeError, 'Keyword method did not work: rescue'
|
||||
end
|
||||
|
||||
if kw.retry != 'retry' then
|
||||
raise RuntimeError, 'Keyword method did not work: retry'
|
||||
end
|
||||
|
||||
if kw.return != 'return' then
|
||||
raise RuntimeError, 'Keyword method did not work: return'
|
||||
end
|
||||
|
||||
if kw.self != 'self' then
|
||||
raise RuntimeError, 'Keyword method did not work: self'
|
||||
end
|
||||
|
||||
if kw.super != 'super' then
|
||||
raise RuntimeError, 'Keyword method did not work: super'
|
||||
end
|
||||
|
||||
if kw.then != 'then' then
|
||||
raise RuntimeError, 'Keyword method did not work: then'
|
||||
end
|
||||
|
||||
if kw.true != 'true' then
|
||||
raise RuntimeError, 'Keyword method did not work: true'
|
||||
end
|
||||
|
||||
if kw.under != 'under' then
|
||||
raise RuntimeError, 'Keyword method did not work: under'
|
||||
end
|
||||
|
||||
if kw.unless != 'unless' then
|
||||
raise RuntimeError, 'Keyword method did not work: unless'
|
||||
end
|
||||
|
||||
if kw.until != 'until' then
|
||||
raise RuntimeError, 'Keyword method did not work: until'
|
||||
end
|
||||
|
||||
if kw.when != 'when' then
|
||||
raise RuntimeError, 'Keyword method did not work: when'
|
||||
end
|
||||
|
||||
if kw.while != 'while' then
|
||||
raise RuntimeError, 'Keyword method did not work: while'
|
||||
end
|
||||
|
||||
if kw.yield != 'yield' then
|
||||
raise RuntimeError, 'Keyword method did not work: yield'
|
||||
end
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue