Merge branch 'master' of git://factorcode.org/git/factor
[factor/jcg.git] / basis / mime / multipart / multipart-tests.factor
blobe1bf0483bcff84cd44afec52cf6e51f035ff3577
1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io.encodings.ascii io.files io.files.unique kernel
4 mime.multipart tools.test io.streams.duplex io multiline
5 assocs ;
6 IN: mime.multipart.tests
8 : upload-separator ( -- seq )
9    "----WebKitFormBoundary6odjpVPXIighAE2L" ;
11 : upload ( -- seq )
12    "------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" ;
14 : mime-test-stream ( -- stream )
15    upload
16    "mime" "test" make-unique-file ascii
17    [ set-file-contents ] [ <file-reader> ] 2bi ;
19 [ ] [ mime-test-stream [ ] with-input-stream ] unit-test
21 [ t ] [
22     mime-test-stream [ upload-separator parse-multipart ] with-input-stream
23     nip "\"up.txt\"" swap key?
24 ] unit-test
26 [ t ] [
27     mime-test-stream [ upload-separator parse-multipart ] with-input-stream
28     drop "\"text1\"" swap key?
29 ] unit-test