Skip to content

Instantly share code, notes, and snippets.

@cbilson
Created January 13, 2009 12:22
Show Gist options
  • Save cbilson/46424 to your computer and use it in GitHub Desktop.
Save cbilson/46424 to your computer and use it in GitHub Desktop.
#light
namespace SqlFuckTests
open NUnit.Framework
// Didn't find the extension methods you referenced, so made these
module Extensions =
type System.Object with
member this.ShouldBeOfType (a:System.Type) : unit =
Assert.IsAssignableFrom(a, this)
member this.ShouldEqual expected : unit =
Assert.AreEqual(expected, this)
open Extensions
// stubs of your types
type Token() =
type Verb(v:string) =
inherit Token()
let mutable value = v
member x.Value
with get() = value
and set(v) = value <- v
type Scanner() =
member x.NextToken() = new Verb("create")
[<AbstractClass>] // f# infers abstractness but warns unless you add attribute
type using_scanner() =
// no automatic properties in f#, so we need fields
let mutable token = new Token() // = null not allowed in f#
let mutable scanner = new Scanner()
// no protected in f#, so leaving these public
member x.Token
with get() = token
and set(value) = token <- value
member x.Scanner
with get() = scanner
and set(value) = scanner <- value
abstract Context : unit
member x.Setup() =
let sql = @"CREATE TABLE `gameratings_db`.`testtable` (
`id` bigint(20) DEFAULT NULL,
`test` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
scanner <- new Scanner()
x.Context
[<TestFixture>]
type When_word_create_is_parsed() =
inherit using_scanner()
override x.Context =
x.Token <- x.Scanner.NextToken()
[<Test>]
member x.Should_be_parsed_as_verb() =
x.Token.ShouldBeOfType(typeof<Verb>)
[<Test>]
member x.Should_indicate_that_verb_is_create() =
(x.Token :?> Verb).Value.ShouldEqual("verb")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment