Apr. 23rd, 2014
So, I read "GET /biteme HTTP 1.0" from the socket, and get "GT /biteme HTTP 1.0", and look into the source code re:wtf, and here's what I see:
class BufferedLineIterator extends AbstractIterator[String] with Iterator[String] {
// Don't want to lose a buffered char sitting in iter either. Yes,
// this is ridiculous, but if I can't get rid of Source, and all the
// Iterator bits are designed into Source, and people create Sources
// in the repl, and the repl calls toString for the result line, and
// that calls hasNext to find out if they're empty, and that leads
// to chars being buffered, and no, I don't work here, they left a
// door unlocked.
private val lineReader: BufferedReader = {
// To avoid inflicting this silliness indiscriminately, we can
// skip it if the char reader was never created: and almost always
// it will not have been created, since getLines will be called
// immediately on the source.
if (charReaderCreated && iter.hasNext) {
val pb = new PushbackReader(charReader)
pb unread iter.next()
new BufferedReader(pb, bufferSize)
}
else charReader
}
here's a piece of code I wrote
Apr. 23rd, 2014 05:01 pmWas kind of way tired of checking whether this or that stuff works in a browser by running it in real-life code, really; and eventually stopped everything and wrote this code:
What happens here: I launch a server I wrote (60 lines of Scala, in total, under the cut), and a Selenium browser, and I load the test page before the test, and in my test case, just one here, I run some JavaScript, and check that it works. Then in
( Read more... )
class Tools_js_Test extends Specification with BeforeAfterExample {
val server = new WebServer(7777, "biteme" -> (() => "<html><body><h1>this is a test</h1></body>"))
var browser:SeleniumBrowsingExec = _
def before = {
server.start
browser = new SeleniumBrowsingExec(NoProps)
browser.loadPage(page) must_== OK
}
def after = {
server.stop
browser.dispose()
}
val page = Url("http://localhost:7777/biteme")
"Browser" should {
"load library" in {
browser.runJS(JavaScript.library)
val loaded = browser.runJS("return window.OK")
loaded must_== Good("OK")
}
}
}
What happens here: I launch a server I wrote (60 lines of Scala, in total, under the cut), and a Selenium browser, and I load the test page before the test, and in my test case, just one here, I run some JavaScript, and check that it works. Then in
after method I close the server and the browser, and that's it. ( Read more... )
