]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/mime/multipart/multipart-tests.factor
factor: add newlines to .factor files
[factor.git] / basis / mime / multipart / multipart-tests.factor
index 229c64859bfae4c79afb0bfee09cfabda2d61487..d2644f2974482b55daf752988a83848fec559225 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs continuations fry http.server io
-io.encodings.ascii io.files io.files.unique
+io.encodings.ascii io.files io.files.temp io.files.unique
 io.servers io.streams.duplex io.streams.string
-kernel math.ranges mime.multipart multiline namespaces random
+kernel ranges mime.multipart multiline namespaces random
 sequences sorting strings threads tools.test ;
 IN: mime.multipart.tests
 
@@ -13,22 +13,22 @@ CONSTANT: upload1 "------WebKitFormBoundary6odjpVPXIighAE2L\r\nContent-Dispositi
 
 : mime-test-stream ( -- stream )
    upload1
-   "mime" "test" make-unique-file ascii
-   [ set-file-contents ] [ <file-reader> ] 2bi ;
+   [ "mime" "test" unique-file ] with-temp-directory
+   ascii [ set-file-contents ] [ <file-reader> ] 2bi ;
 
-[ ] [ mime-test-stream [ ] with-input-stream ] unit-test
+{ } [ mime-test-stream [ ] with-input-stream ] unit-test
 
-[ t ] [
+{ t } [
     mime-test-stream [ separator1 parse-multipart ] with-input-stream
     "file1" swap key?
 ] unit-test
 
-[ t ] [
+{ t } [
     mime-test-stream [ separator1 parse-multipart ] with-input-stream
     "file1" swap key?
 ] unit-test
 
-[ t ] [
+{ t } [
     mime-test-stream [ separator1 parse-multipart ] with-input-stream
     "file1" of filename>> "up.txt" =
 ] unit-test
@@ -36,14 +36,14 @@ CONSTANT: upload1 "------WebKitFormBoundary6odjpVPXIighAE2L\r\nContent-Dispositi
 CONSTANT: separator2 "768de80194d942619886d23f1337aa15"
 CONSTANT: upload2 "--768de80194d942619886d23f1337aa15\r\nContent-Disposition: form-data; name=\"text\"; filename=\"upload.txt\"\r\nContent-Type: text/plain\r\n\r\nhello\r\n--768de80194d942619886d23f1337aa15--\r\n"
 
-[
+{
     "upload.txt"
     H{
         { "content-disposition"
           "form-data; name=\"text\"; filename=\"upload.txt\"" }
         { "content-type" "text/plain" }
     }
-] [
+} [
     upload2 [ separator2 parse-multipart ] with-string-reader
     "text" of [ filename>> ] [ headers>> ] bi
 ] unit-test
@@ -51,9 +51,9 @@ CONSTANT: upload2 "--768de80194d942619886d23f1337aa15\r\nContent-Disposition: fo
 CONSTANT: separator3 "3f116598c7f0431b9f98148ed235c822"
 CONSTANT: upload3 "--3f116598c7f0431b9f98148ed235c822\r\nContent-Disposition: form-data; name=\"text\"; filename=\"upload.txt\"\r\n\r\nhello\r\n--3f116598c7f0431b9f98148ed235c822\r\nContent-Disposition: form-data; name=\"text2\"; filename=\"upload.txt\"\r\n\r\nhello\r\n--3f116598c7f0431b9f98148ed235c822--\r\n"
 
-[
+{
     { "text" "text2" }
-] [
+} [
     upload3 [ separator3 parse-multipart ] with-string-reader
     keys natural-sort
 ] unit-test
@@ -73,7 +73,15 @@ SYMBOL: mime-test-server
 : a-stream ( n -- stream )
     CHAR: a <string> <string-reader> ;
 
-[ ] [
+{ } [
     [
     ] with-test-server
 ] unit-test
+
+[
+    "--\r\n\r\n" <string-reader> [
+        "\r\n\r\n" <multipart>
+        "\r\n\r\n" parse-multipart
+    ] with-input-stream
+] [ mime-decoding-ran-out-of-bytes? ] must-fail-with
+