1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
# -*- encoding: utf-8 -*-
module IOSpecs
class SubIO < IO
end
def self.collector
Proc.new { |x| ScratchPad << x }
end
def self.lines
[ "Voici la ligne une.\n",
"Qui \303\250 la linea due.\n",
"\n",
"\n",
"Aqu\303\255 est\303\241 la l\303\255nea tres.\n",
"Ist hier Linie vier.\n",
"\n",
"Est\303\241 aqui a linha cinco.\n",
"Here is line six.\n" ]
end
def self.lines_limit
[ "Voici la l",
"igne une.\n",
"Qui è la ",
"linea due.",
"\n",
"\n",
"\n",
"Aquí está",
" la línea",
" tres.\n",
"Ist hier L",
"inie vier.",
"\n",
"\n",
"Está aqui",
" a linha c",
"inco.\n",
"Here is li",
"ne six.\n" ]
end
def self.lines_space_separator_limit
[ "Voici ",
"la ",
"ligne ",
"une.\nQui ",
"è ",
"la ",
"linea ",
"due.\n\n\nAqu",
"í ",
"está ",
"la ",
"línea ",
"tres.\nIst ",
"hier ",
"Linie ",
"vier.\n\nEst",
"á ",
"aqui ",
"a ",
"linha ",
"cinco.\nHer",
"e ",
"is ",
"line ",
"six.\n" ]
end
def self.lines_r_separator
[ "Voici la ligne une.\nQui \303\250 la linea due.\n\n\n" \
"Aqu\303\255 est\303\241 la l\303\255nea tr",
"es.\nIst hier",
" Linie vier",
".\n\nEst\303\241 aqui a linha cinco.\nHer",
"e is line six.\n" ]
end
def self.lines_empty_separator
[ "Voici la ligne une.\nQui \303\250 la linea due.\n\n",
"Aqu\303\255 est\303\241 la l\303\255nea tres.\nIst hier Linie vier.\n\n",
"Est\303\241 aqui a linha cinco.\nHere is line six.\n" ]
end
def self.lines_space_separator
[ "Voici ", "la ", "ligne ", "une.\nQui ",
"\303\250 ", "la ", "linea ", "due.\n\n\nAqu\303\255 ",
"est\303\241 ", "la ", "l\303\255nea ", "tres.\nIst ",
"hier ", "Linie ", "vier.\n\nEst\303\241 ", "aqui ", "a ",
"linha ", "cinco.\nHere ", "is ", "line ", "six.\n" ]
end
def self.lines_arbitrary_separator
[ "Voici la ligne une.\nQui \303\250",
" la linea due.\n\n\nAqu\303\255 est\303\241 la l\303\255nea tres.\n" \
"Ist hier Linie vier.\n\nEst\303\241 aqui a linha cinco.\nHere is line six.\n" ]
end
def self.paragraphs
[ "Voici la ligne une.\nQui \303\250 la linea due.\n\n",
"Aqu\303\255 est\303\241 la l\303\255nea tres.\nIst hier Linie vier.\n\n",
"Est\303\241 aqui a linha cinco.\nHere is line six.\n" ]
end
# Creates an IO instance for an existing fixture file. The
# file should obviously not be deleted.
def self.io_fixture(name, options_or_mode="r:utf-8")
path = fixture __FILE__, name
name = path if File.exists? path
new_io name, options_or_mode
end
# Returns a closed instance of IO that was opened to reference
# a fixture file (i.e. the IO instance was perfectly valid at
# one point but is now closed).
def self.closed_io
io = io_fixture "lines.txt"
io.close
io
end
# Creates a pipe-based IO fixture containing the specified
# contents
def self.pipe_fixture(content)
source, sink = IO.pipe
sink.write content
sink.close
source
end
# Defines +method+ on +obj+ using the provided +block+. This
# special helper is needed for e.g. IO.open specs to avoid
# mock methods preventing IO#close from running.
def self.io_mock(obj, method, &block)
obj.singleton_class.send(:define_method, method, &block)
end
module CopyStream
def self.from=(from)
@from = from
end
def self.from
@from
end
end
class CopyStreamRead
def initialize(io)
@io = io
end
def read(size, buf=nil)
@io.read size, buf
end
end
class CopyStreamReadPartial
def initialize(io)
@io = io
end
def readpartial(size, buf=nil)
@io.readpartial size, buf
end
end
end
|