factor/basis/mime/multipart/multipart-tests.factor

36 lines
1.4 KiB
Factor
Raw Normal View History

2009-01-19 19:01:13 -05:00
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: io.encodings.ascii io.files io.files.unique kernel
mime.multipart tools.test io.streams.duplex io multiline
2009-01-26 18:29:50 -05:00
assocs accessors ;
IN: mime.multipart.tests
2009-01-19 19:01:13 -05:00
: upload-separator ( -- seq )
"----WebKitFormBoundary6odjpVPXIighAE2L" ;
2009-01-19 19:01:13 -05:00
: upload ( -- seq )
"------WebKitFormBoundary6odjpVPXIighAE2L\r\nContent-Disposition: form-data; name=\"file1\"; filename=\"up.txt\"\r\nContent-Type: text/plain\r\n\r\nuploaded!\n\r\n------WebKitFormBoundary6odjpVPXIighAE2L\r\nContent-Disposition: form-data; name=\"file2\"; filename=\"\"\r\n\r\n\r\n------WebKitFormBoundary6odjpVPXIighAE2L\r\nContent-Disposition: form-data; name=\"file3\"; filename=\"\"\r\n\r\n\r\n------WebKitFormBoundary6odjpVPXIighAE2L\r\nContent-Disposition: form-data; name=\"text1\"\r\n\r\nlol\r\n------WebKitFormBoundary6odjpVPXIighAE2L--\r\n" ;
2009-01-19 19:01:13 -05:00
: mime-test-stream ( -- stream )
upload
"mime" "test" make-unique-file ascii
[ set-file-contents ] [ <file-reader> ] 2bi ;
2009-01-19 19:01:13 -05:00
[ ] [ mime-test-stream [ ] with-input-stream ] unit-test
2009-01-19 19:01:13 -05:00
[ t ] [
mime-test-stream [ upload-separator parse-multipart ] with-input-stream
2009-01-26 18:29:50 -05:00
"file1" swap key?
] unit-test
2009-01-19 19:01:13 -05:00
[ t ] [
mime-test-stream [ upload-separator parse-multipart ] with-input-stream
2009-01-26 18:29:50 -05:00
"file1" swap key?
] unit-test
[ t ] [
mime-test-stream [ upload-separator parse-multipart ] with-input-stream
"file1" swap at filename>> "up.txt" =
] unit-test