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
|
|
|
|
assocs ;
|
2008-11-21 23:10:58 -05:00
|
|
|
IN: mime.multipart.tests
|
|
|
|
|
2009-01-19 19:01:13 -05:00
|
|
|
: upload-separator ( -- seq )
|
|
|
|
"----WebKitFormBoundary6odjpVPXIighAE2L" ;
|
2008-11-21 23:10:58 -05:00
|
|
|
|
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" ;
|
2008-11-21 23:10:58 -05:00
|
|
|
|
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 ;
|
2008-11-21 23:10:58 -05:00
|
|
|
|
2009-01-19 19:01:13 -05:00
|
|
|
[ ] [ mime-test-stream [ ] with-input-stream ] unit-test
|
2008-11-21 23:10:58 -05:00
|
|
|
|
2009-01-19 19:01:13 -05:00
|
|
|
[ t ] [
|
|
|
|
mime-test-stream [ upload-separator parse-multipart ] with-input-stream
|
2009-01-20 14:23:58 -05:00
|
|
|
drop "\"up.txt\"" swap key?
|
2008-11-21 23:10:58 -05:00
|
|
|
] unit-test
|
|
|
|
|
2009-01-19 19:01:13 -05:00
|
|
|
[ t ] [
|
|
|
|
mime-test-stream [ upload-separator parse-multipart ] with-input-stream
|
2009-01-20 14:23:58 -05:00
|
|
|
nip "\"text1\"" swap key?
|
2008-11-21 23:10:58 -05:00
|
|
|
] unit-test
|