Moved unstable/cce/text to unstable/text.

This commit is contained in:
Carl Eastlund 2010-05-29 00:23:21 -04:00
parent 8d10a6343b
commit 6bcf77fe65
12 changed files with 172 additions and 161 deletions

View File

@ -2,7 +2,9 @@
(provide test (provide test
test-ok check-ok test-ok check-ok
test-bad check-bad) test-bad check-bad
check-not
with/c)
(require rackunit racket/pretty) (require rackunit racket/pretty)
@ -18,3 +20,18 @@
(define (pretty-format/write x) (define (pretty-format/write x)
(with-output-to-string (with-output-to-string
(lambda () (pretty-write x)))) (lambda () (pretty-write x))))
(define-syntax-rule (with/c c e)
(let () (with-contract value ([value c]) (define value e)) value))
(define-check (check-not compare actual expected)
(with-check-info*
(list (make-check-info 'comparison compare)
(make-check-actual actual)
(make-check-expected expected))
(lambda ()
(let* ([result (compare actual expected)])
(when result
(with-check-info*
(list (make-check-info 'result result))
(lambda () (fail-check))))))))

View File

@ -0,0 +1,133 @@
#lang racket
(require rackunit rackunit/text-ui unstable/text "helpers.rkt")
(run-tests
(test-suite "text.ss"
(test-suite "text/c"
(test-ok (with/c text/c "text"))
(test-ok (with/c text/c #"text"))
(test-ok (with/c text/c 'text))
(test-ok (with/c text/c '#:text))
(test-ok (with/c text/c #'"text"))
(test-ok (with/c text/c #'#"text"))
(test-ok (with/c text/c #'text))
(test-ok (with/c text/c #'#:text))
(test-bad (with/c text/c '(not text))))
(test-suite "text?"
(test-case "accept string"
(check-pred text? "text"))
(test-case "accept byte string"
(check-pred text? #"text"))
(test-case "accept symbol"
(check-pred text? 'text))
(test-case "accept keyword"
(check-pred text? '#:text))
(test-case "accept string literal"
(check-pred text? #'"text"))
(test-case "accept byte string literal"
(check-pred text? #'#"text"))
(test-case "accept identifier"
(check-pred text? #'text))
(test-case "accept keyword literal"
(check-pred text? #'#:text))
(test-case "reject non-text"
(check-false (text? '(not text)))))
(test-suite "string-literal?"
(test-case "accept" (check-true (string-literal? #'"string")))
(test-case "reject" (check-false (string-literal? "string"))))
(test-suite "keyword-literal?"
(test-case "accept" (check-true (keyword-literal? #'#:keyword)))
(test-case "reject" (check-false (keyword-literal? '#:keyword))))
(test-suite "bytes-literal?"
(test-case "accept" (check-true (bytes-literal? #'#"bytes")))
(test-case "reject" (check-false (bytes-literal? #"bytes"))))
(test-suite "text=?"
(test-case "string = string"
(check text=? "abc" (string-copy "abc")))
(test-case "string != string"
(check-not text=? "abc" (string-copy "cba")))
(test-case "string = identifier"
(check text=? "car" #'car))
(test-case "string != identifier"
(check-not text=? "car" #'cdr))
(test-case "identifier = identifier, different bindings"
(check text=? #'car (datum->syntax #f 'car)))
(test-case "identifier != identifier, no bindings"
(check-not text=? #'UNBOUND (datum->syntax #f 'ALSO-UNBOUND))))
(test-suite "text<?"
(test-case "string < string"
(check text<? "abc" "def"))
(test-case "string !< string"
(check-not text<? "abc" "abc"))
(test-case "string < identifier"
(check text<? "abc" #'def))
(test-case "string !< identifier"
(check-not text<? "abc" #'abc)))
(test-suite "text<=?"
(test-case "string <= string"
(check text<=? "abc" "abc"))
(test-case "string !<= string"
(check-not text<=? "def" "abc"))
(test-case "string <= identifier"
(check text<=? "abc" #'abc))
(test-case "string !<= identifier"
(check-not text<=? "def" #'abc)))
(test-suite "text>?"
(test-case "string > string"
(check text>? "def" "abc"))
(test-case "string !> string"
(check-not text>? "abc" "abc"))
(test-case "string > identifier"
(check text>? "def" #'abc))
(test-case "string !> identifier"
(check-not text>? "abc" #'abc)))
(test-suite "text>=?"
(test-case "string >= string"
(check text>=? "abc" "abc"))
(test-case "string !>= string"
(check-not text>=? "abc" "def"))
(test-case "string >= identifier"
(check text>=? "abc" #'abc))
(test-case "string !>= identifier"
(check-not text>=? "abc" #'def)))
(test-suite "text->string"
(test-case "single" (check-equal? (text->string 'abc) "abc"))
(test-case "multiple" (check-equal? (text->string 'a "b" #'c) "abc")))
(test-suite "text->symbol"
(test-case "single" (check-equal? (text->symbol "abc") 'abc))
(test-case "multiple" (check-equal? (text->symbol 'a "b" #'c) 'abc)))
(test-suite "text->keyword"
(test-case "single" (check-equal? (text->keyword #'abc) '#:abc))
(test-case "multiple" (check-equal? (text->keyword 'a "b" #'c) '#:abc)))
(test-suite "text->bytes"
(test-case "single" (check-equal? (text->bytes "abc") #"abc"))
(test-case "multiple" (check-equal? (text->bytes 'a "b" #'c) #"abc")))
(test-suite "text->identifier"
(test-case "single, no context"
(check-equal? (syntax-e (text->identifier "abc")) 'abc))
(test-case "multiple w/ context"
(check bound-identifier=?
(text->identifier #:stx #'here 'a "b" #'c)
#'abc)))
(test-suite "text->string-literal"
(test-case "single"
(check-equal? (syntax-e (text->string-literal '#:abc)) "abc"))
(test-case "multiple"
(check-equal?
(syntax-e (text->string-literal #:stx #'here 'a "b" #'c))
"abc")))
(test-suite "text->keyword-literal"
(test-case "single"
(check-equal? (syntax-e (text->keyword-literal #"abc")) '#:abc))
(test-case "multiple"
(check-equal?
(syntax-e (text->keyword-literal #:stx #'here 'a "b" #'c))
'#:abc)))
(test-suite "text->bytes-literal"
(test-case "single"
(check-equal? (syntax-e (text->bytes-literal 'abc)) #"abc"))
(test-case "multiple"
(check-equal?
(syntax-e (text->bytes-literal #:stx #'here 'a "b" #'c))
#"abc")))))

View File

@ -2,8 +2,8 @@
(require scheme/contract (require scheme/contract
scheme/match scheme/match
unstable/text
(only-in unstable/syntax with-syntax*) (only-in unstable/syntax with-syntax*)
"../text.ss"
(for-syntax scheme/base)) (for-syntax scheme/base))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -12,7 +12,6 @@
@include-section["values.scrbl"] @include-section["values.scrbl"]
@include-section["text.scrbl"]
@include-section["regexp.scrbl"] @include-section["regexp.scrbl"]
@include-section["web.scrbl"] @include-section["web.scrbl"]

View File

@ -29,7 +29,8 @@ described by the following grammar:
[value text] [value text]
] ]
Here, @scheme[text] is any of the datatypes described in @secref["cce-text"]. Here, @scheme[text] is any of the datatypes described in
@secref["unstable-text"].
} }
@defthing[xexpr/c flat-contract?]{ @defthing[xexpr/c flat-contract?]{

View File

@ -8,14 +8,14 @@
syntax/kerncase syntax/kerncase
setup/main-collects setup/main-collects
planet/planet-archives planet/planet-archives
unstable/text
(for-template scheme/base) (for-template scheme/base)
(for-syntax scheme/base) (for-syntax scheme/base)
(for-label scheme) (for-label scheme)
"private/syntax-core.ss" "private/syntax-core.ss"
"private/define-core.ss" "private/define-core.ss"
(for-template "private/define-core.ss") (for-template "private/define-core.ss")
"contract.ss" "contract.ss")
"text.ss")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;

View File

@ -18,7 +18,6 @@
"test-scribble.ss" "test-scribble.ss"
"test-set.ss" "test-set.ss"
"test-syntax.ss" "test-syntax.ss"
"test-text.ss"
"test-values.ss" "test-values.ss"
"test-web.ss") "test-web.ss")
@ -41,6 +40,5 @@
scribble-suite scribble-suite
set-suite set-suite
syntax-suite syntax-suite
text-suite
values-suite values-suite
web-suite)) web-suite))

View File

@ -1,136 +0,0 @@
#lang scheme
(require "checks.ss"
"../text.ss")
(provide text-suite)
(define text-suite
(test-suite "text.ss"
(test-suite "text/c"
(test-ok (with/c text/c "text"))
(test-ok (with/c text/c #"text"))
(test-ok (with/c text/c 'text))
(test-ok (with/c text/c '#:text))
(test-ok (with/c text/c #'"text"))
(test-ok (with/c text/c #'#"text"))
(test-ok (with/c text/c #'text))
(test-ok (with/c text/c #'#:text))
(test-bad (with/c text/c '(not text))))
(test-suite "text?"
(test-case "accept string"
(check-pred text? "text"))
(test-case "accept byte string"
(check-pred text? #"text"))
(test-case "accept symbol"
(check-pred text? 'text))
(test-case "accept keyword"
(check-pred text? '#:text))
(test-case "accept string literal"
(check-pred text? #'"text"))
(test-case "accept byte string literal"
(check-pred text? #'#"text"))
(test-case "accept identifier"
(check-pred text? #'text))
(test-case "accept keyword literal"
(check-pred text? #'#:text))
(test-case "reject non-text"
(check-false (text? '(not text)))))
(test-suite "string-literal?"
(test-case "accept" (check-true (string-literal? #'"string")))
(test-case "reject" (check-false (string-literal? "string"))))
(test-suite "keyword-literal?"
(test-case "accept" (check-true (keyword-literal? #'#:keyword)))
(test-case "reject" (check-false (keyword-literal? '#:keyword))))
(test-suite "bytes-literal?"
(test-case "accept" (check-true (bytes-literal? #'#"bytes")))
(test-case "reject" (check-false (bytes-literal? #"bytes"))))
(test-suite "text=?"
(test-case "string = string"
(check text=? "abc" (string-copy "abc")))
(test-case "string != string"
(check-not text=? "abc" (string-copy "cba")))
(test-case "string = identifier"
(check text=? "car" #'car))
(test-case "string != identifier"
(check-not text=? "car" #'cdr))
(test-case "identifier = identifier, different bindings"
(check text=? #'car (datum->syntax #f 'car)))
(test-case "identifier != identifier, no bindings"
(check-not text=? #'UNBOUND (datum->syntax #f 'ALSO-UNBOUND))))
(test-suite "text<?"
(test-case "string < string"
(check text<? "abc" "def"))
(test-case "string !< string"
(check-not text<? "abc" "abc"))
(test-case "string < identifier"
(check text<? "abc" #'def))
(test-case "string !< identifier"
(check-not text<? "abc" #'abc)))
(test-suite "text<=?"
(test-case "string <= string"
(check text<=? "abc" "abc"))
(test-case "string !<= string"
(check-not text<=? "def" "abc"))
(test-case "string <= identifier"
(check text<=? "abc" #'abc))
(test-case "string !<= identifier"
(check-not text<=? "def" #'abc)))
(test-suite "text>?"
(test-case "string > string"
(check text>? "def" "abc"))
(test-case "string !> string"
(check-not text>? "abc" "abc"))
(test-case "string > identifier"
(check text>? "def" #'abc))
(test-case "string !> identifier"
(check-not text>? "abc" #'abc)))
(test-suite "text>=?"
(test-case "string >= string"
(check text>=? "abc" "abc"))
(test-case "string !>= string"
(check-not text>=? "abc" "def"))
(test-case "string >= identifier"
(check text>=? "abc" #'abc))
(test-case "string !>= identifier"
(check-not text>=? "abc" #'def)))
(test-suite "text->string"
(test-case "single" (check-equal? (text->string 'abc) "abc"))
(test-case "multiple" (check-equal? (text->string 'a "b" #'c) "abc")))
(test-suite "text->symbol"
(test-case "single" (check-equal? (text->symbol "abc") 'abc))
(test-case "multiple" (check-equal? (text->symbol 'a "b" #'c) 'abc)))
(test-suite "text->keyword"
(test-case "single" (check-equal? (text->keyword #'abc) '#:abc))
(test-case "multiple" (check-equal? (text->keyword 'a "b" #'c) '#:abc)))
(test-suite "text->bytes"
(test-case "single" (check-equal? (text->bytes "abc") #"abc"))
(test-case "multiple" (check-equal? (text->bytes 'a "b" #'c) #"abc")))
(test-suite "text->identifier"
(test-case "single, no context"
(check-equal? (syntax-e (text->identifier "abc")) 'abc))
(test-case "multiple w/ context"
(check bound-identifier=?
(text->identifier #:stx #'here 'a "b" #'c)
#'abc)))
(test-suite "text->string-literal"
(test-case "single"
(check-equal? (syntax-e (text->string-literal '#:abc)) "abc"))
(test-case "multiple"
(check-equal?
(syntax-e (text->string-literal #:stx #'here 'a "b" #'c))
"abc")))
(test-suite "text->keyword-literal"
(test-case "single"
(check-equal? (syntax-e (text->keyword-literal #"abc")) '#:abc))
(test-case "multiple"
(check-equal?
(syntax-e (text->keyword-literal #:stx #'here 'a "b" #'c))
'#:abc)))
(test-suite "text->bytes-literal"
(test-case "single"
(check-equal? (syntax-e (text->bytes-literal 'abc)) #"abc"))
(test-case "multiple"
(check-equal?
(syntax-e (text->bytes-literal #:stx #'here 'a "b" #'c))
#"abc")))))

View File

@ -1,8 +1,8 @@
#lang scheme #lang scheme
(require xml (require xml
unstable/function unstable/function
"define.ss" unstable/text
"text.ss") "define.ss")
;; css/c : FlatContract ;; css/c : FlatContract
;; Recognizes representations of Cascading Style Sheets. ;; Recognizes representations of Cascading Style Sheets.

View File

@ -1,13 +1,11 @@
#lang scribble/doc #lang scribble/manual
@(require scribble/manual @(require scribble/eval "utils.rkt" (for-label racket unstable/text))
scribble/eval
"../scribble.ss"
"eval.ss")
@(require (for-label scheme unstable/cce/text))
@title[#:style 'quiet #:tag "cce-text"]{Text Representations} @title[#:tag "unstable-text"]{Text Representations}
@defmodule[unstable/cce/text] @defmodule[unstable/text]
@unstable[@author+email["Carl Eastlund" "cce@racket-lang.org"]]
This module provides tools for manipulating and converting textual data. This module provides tools for manipulating and converting textual data.
@ -22,7 +20,7 @@ This contract and predicate recognize text values: strings, byte strings,
symbols, and keywords, as well as syntax objects containing them. symbols, and keywords, as well as syntax objects containing them.
@defexamples[ @defexamples[
#:eval (evaluator 'unstable/cce/text) #:eval (eval/require 'unstable/text)
(text? "text") (text? "text")
(text? #"text") (text? #"text")
(text? 'text) (text? 'text)
@ -45,7 +43,7 @@ symbols, and keywords, as well as syntax objects containing them.
These predicates recognize specific text types stored in syntax objects. These predicates recognize specific text types stored in syntax objects.
@defexamples[ @defexamples[
#:eval (evaluator 'unstable/cce/text) #:eval (eval/require 'unstable/text)
(string-literal? #'"literal") (string-literal? #'"literal")
(string-literal? "not literal") (string-literal? "not literal")
(bytes-literal? #'#"literal") (bytes-literal? #'#"literal")
@ -82,7 +80,7 @@ These functions convert text values to specific types. They concatenate each
and back of the result and @scheme[between] between each argument. and back of the result and @scheme[between] between each argument.
@defexamples[ @defexamples[
#:eval (evaluator 'unstable/cce/text) #:eval (eval/require 'unstable/text)
(text->string #"concat" #'enate) (text->string #"concat" #'enate)
(text->bytes #:between "-" 'concat #'#:enate) (text->bytes #:between "-" 'concat #'#:enate)
(text->symbol #:before "(" #:after ")" '#:concat #'"enate") (text->symbol #:before "(" #:after ")" '#:concat #'"enate")
@ -124,7 +122,7 @@ syntax object properties from the @scheme[stx] argument. They concatenate each
and back of the result and @scheme[between] between each argument. and back of the result and @scheme[between] between each argument.
@defexamples[ @defexamples[
#:eval (evaluator 'unstable/cce/text) #:eval (eval/require 'unstable/text)
(text->string-literal #"concat" #'enate) (text->string-literal #"concat" #'enate)
(text->bytes-literal #:between "-" 'concat #'#:enate) (text->bytes-literal #:between "-" 'concat #'#:enate)
(text->identifier #:before "(" #:after ")" (text->identifier #:before "(" #:after ")"
@ -159,7 +157,7 @@ equivalent to:
] ]
@defexamples[ @defexamples[
#:eval (evaluator 'unstable/cce/text) #:eval (eval/require 'unstable/text)
(text=? #"x" #'y) (text=? #"x" #'y)
(text<? #"x" #'y) (text<? #"x" #'y)
(text<=? #"x" #'y) (text<=? #"x" #'y)

View File

@ -85,6 +85,7 @@ Keep documentation and tests up to date.
@include-section["string.scrbl"] @include-section["string.scrbl"]
@include-section["struct.scrbl"] @include-section["struct.scrbl"]
@include-section["syntax.scrbl"] @include-section["syntax.scrbl"]
@include-section["text.scrbl"]
@include-section["poly-c.scrbl"] @include-section["poly-c.scrbl"]
@include-section["mutated-vars.scrbl"] @include-section["mutated-vars.scrbl"]
@include-section["find.scrbl"] @include-section["find.scrbl"]

View File

@ -1,6 +1,6 @@
#lang scheme/base #lang racket/base
(require scheme/list scheme/match scheme/contract) (require racket/list racket/match racket/contract)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;