/spec/r-fxxk_spec.rb

https://github.com/masarakki/r-fxxk · Ruby · 68 lines · 62 code · 6 blank · 0 comment · 2 complexity · 55c0938fa8802e93c46e77df9ccc46ae MD5 · raw file

  1. require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
  2. class Ook < Brainfuck
  3. nxt 'Ook. Ook?'
  4. prv 'Ook? Ook.'
  5. inc 'Ook. Ook.'
  6. dec 'Ook! Ook!'
  7. put 'Ook! Ook.'
  8. get 'Ook. Ook!'
  9. opn 'Ook! Ook?'
  10. cls 'Ook? Ook!'
  11. end
  12. def src(file)
  13. open(File.expand_path(File.dirname(__FILE__) + "/test_data/#{file}")).read
  14. end
  15. describe Brainfuck do
  16. context 'default Brainfuck' do
  17. subject { Brainfuck.new }
  18. its(:nxt) { should eq '>' }
  19. its(:prv) { should eq '<' }
  20. its(:inc) { should eq '+' }
  21. its(:dec) { should eq '-' }
  22. its(:put) { should eq '.' }
  23. its(:get) { should eq ',' }
  24. its(:opn) { should eq '[' }
  25. its(:cls) { should eq ']' }
  26. it "fuck(hello.bf) should be 'Hello World\\n'" do
  27. subject.fuck(src('hello.bf')).should eq "Hello World!\n"
  28. end
  29. end
  30. context 'customize in initialize' do
  31. subject { Brainfuck.new(nxt: 'M', prv: 'O', inc: 'N', dec: 'A', get: 'm', put: 'o', opn: 'n', cls: 'a') }
  32. its(:nxt) { should eq 'M' }
  33. its(:prv) { should eq 'O' }
  34. its(:inc) { should eq 'N' }
  35. its(:dec) { should eq 'A' }
  36. its(:get) { should eq 'm' }
  37. its(:put) { should eq 'o' }
  38. its(:opn) { should eq 'n' }
  39. its(:cls) { should eq 'a' }
  40. it "fuck(hello.mona) should be 'Hello World\\n'" do
  41. subject.fuck(src('hello.mona')).should eq "Hello World!\n"
  42. end
  43. it "translate(Brainfuck.new, hello.bf) should == hello.mona" do
  44. subject.translate(Brainfuck, src('hello.bf')).strip.should eq src('hello.mona').strip
  45. end
  46. its(:hello_world) { should == src('hello.mona').strip }
  47. end
  48. context 'customized class' do
  49. subject { Ook.new }
  50. its(:nxt) { should eq 'Ook. Ook?' }
  51. its(:prv) { should eq 'Ook? Ook.' }
  52. its(:inc) { should eq 'Ook. Ook.' }
  53. its(:dec) { should eq 'Ook! Ook!' }
  54. its(:put) { should eq 'Ook! Ook.' }
  55. its(:get) { should eq 'Ook. Ook!' }
  56. its(:opn) { should eq 'Ook! Ook?' }
  57. its(:cls) { should eq 'Ook? Ook!' }
  58. it "fuck(hello.ook) should be 'Hello World\\n'" do
  59. subject.fuck(src('hello.ook')).should eq "Hello World!\n"
  60. end
  61. end
  62. end