]> gitweb.factorcode.org Git - factor.git/blob - basis/mime/multipart/multipart-tests.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / mime / multipart / multipart-tests.factor
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
7
8 : upload-separator ( -- seq )
9    "----WebKitFormBoundary6odjpVPXIighAE2L" ;
10
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" ;
13
14 : mime-test-stream ( -- stream )
15    upload
16    "mime" "test" make-unique-file ascii
17    [ set-file-contents ] [ <file-reader> ] 2bi ;
18
19 [ ] [ mime-test-stream [ ] with-input-stream ] unit-test
20
21 [ t ] [
22     mime-test-stream [ upload-separator parse-multipart ] with-input-stream
23     drop "up.txt" swap key?
24 ] unit-test
25
26 [ t ] [
27     mime-test-stream [ upload-separator parse-multipart ] with-input-stream
28     nip "text1" swap key?
29 ] unit-test