Apr. 23rd, 2014

scalarant

Apr. 23rd, 2014 03:41 pm
juan_gandhi: (VP)
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
    }
juan_gandhi: (VP)
Was 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:
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... )
juan_gandhi: (VP)


Но еда не кончилась.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 20th, 2025 11:38 am
Powered by Dreamwidth Studios