mirror of
https://github.com/denoland/deno.git
synced 2024-10-30 09:08:00 -04:00
Reorgnanize repos, examples and tests (denoland/deno_std#105)
Original: c5e6e015b5
This commit is contained in:
parent
7d6a0f64f2
commit
f626b04ebe
44 changed files with 54 additions and 45 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env deno --allow-net --allow-env
|
#!/usr/bin/env deno --allow-net --allow-env
|
||||||
|
|
||||||
import { args, env, exit, readFile } from "deno";
|
import { args, env, exit, readFile } from "deno";
|
||||||
import { parse } from "https://deno.land/x/flags/index.ts";
|
import { parse } from "https://deno.land/x/flags/mod.ts";
|
||||||
|
|
||||||
function pathBase(p: string): string {
|
function pathBase(p: string): string {
|
||||||
const parts = p.split("/");
|
const parts = p.split("/");
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
import { serve } from "https://deno.land/x/net/http.ts";
|
import { serve } from "https://deno.land/x/http/mod.ts";
|
||||||
import {
|
import {
|
||||||
acceptWebSocket,
|
acceptWebSocket,
|
||||||
isWebSocketCloseEvent,
|
isWebSocketCloseEvent,
|
||||||
isWebSocketPingEvent
|
isWebSocketPingEvent
|
||||||
} from "https://deno.land/x/net/ws.ts";
|
} from "https://deno.land/x/ws/mod.ts";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log("websocket server is running on 0.0.0.0:8080");
|
console.log("websocket server is running on 0.0.0.0:8080");
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { args } from "deno";
|
import { args } from "deno";
|
||||||
import { parse } from "./index.ts";
|
import { parse } from "./mod.ts";
|
||||||
|
|
||||||
console.dir(parse(args));
|
console.dir(parse(args));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
// flag boolean true (default all --args to boolean)
|
// flag boolean true (default all --args to boolean)
|
||||||
test(function flagBooleanTrue() {
|
test(function flagBooleanTrue() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
test(function flagBooleanDefaultFalse() {
|
test(function flagBooleanDefaultFalse() {
|
||||||
const argv = parse(["moo"], {
|
const argv = parse(["moo"], {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
test(function hyphen() {
|
test(function hyphen() {
|
||||||
assertEqual(parse(["-n", "-"]), { n: "-", _: [] });
|
assertEqual(parse(["-n", "-"]), { n: "-", _: [] });
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
test(function booleanDefaultTrue() {
|
test(function booleanDefaultTrue() {
|
||||||
const argv = parse([], {
|
const argv = parse([], {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
test(function dottedAlias() {
|
test(function dottedAlias() {
|
||||||
const argv = parse(["--a.b", "22"], {
|
const argv = parse(["--a.b", "22"], {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
test(function short() {
|
test(function short() {
|
||||||
const argv = parse(["-b=123"]);
|
const argv = parse(["-b=123"]);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
test(function longOpts() {
|
test(function longOpts() {
|
||||||
assertEqual(parse(["--bool"]), { bool: true, _: [] });
|
assertEqual(parse(["--bool"]), { bool: true, _: [] });
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
test(function nums() {
|
test(function nums() {
|
||||||
const argv = parse([
|
const argv = parse([
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
test(function _arseArgs() {
|
test(function _arseArgs() {
|
||||||
assertEqual(parse(["--no-moo"]), { moo: false, _: [] });
|
assertEqual(parse(["--no-moo"]), { moo: false, _: [] });
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
test(function numbericShortArgs() {
|
test(function numbericShortArgs() {
|
||||||
assertEqual(parse(["-n123"]), { n: 123, _: [] });
|
assertEqual(parse(["-n123"]), { n: 123, _: [] });
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
// stops parsing on the first non-option when stopEarly is set
|
// stops parsing on the first non-option when stopEarly is set
|
||||||
test(function stopParsing() {
|
test(function stopParsing() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
test(function booleanAndAliasIsNotUnknown() {
|
test(function booleanAndAliasIsNotUnknown() {
|
||||||
const unknown = [];
|
const unknown = [];
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, assertEqual } from "../../testing/mod.ts";
|
import { test, assertEqual } from "../../testing/mod.ts";
|
||||||
import { parse } from "../index.ts";
|
import { parse } from "../mod.ts";
|
||||||
|
|
||||||
test(function whitespaceShouldBeWhitespace() {
|
test(function whitespaceShouldBeWhitespace() {
|
||||||
assertEqual(parse(["-x", "\t"]).x, "\t");
|
assertEqual(parse(["-x", "\t"]).x, "\t");
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { serve } from "https://deno.land/x/net/http.ts";
|
import { serve } from "https://deno.land/x/http/mod.ts";
|
||||||
const s = serve("0.0.0.0:8000");
|
const s = serve("0.0.0.0:8000");
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
@ -22,5 +22,5 @@ A small program for serving local files over HTTP.
|
||||||
Add the following to your `.bash_profile`
|
Add the following to your `.bash_profile`
|
||||||
|
|
||||||
```
|
```
|
||||||
alias file_server="deno https://deno.land/x/net/file_server.ts --allow-net"
|
alias file_server="deno https://deno.land/x/http/file_server.ts --allow-net"
|
||||||
```
|
```
|
|
@ -10,7 +10,7 @@ import {
|
||||||
ServerRequest,
|
ServerRequest,
|
||||||
setContentLength,
|
setContentLength,
|
||||||
Response
|
Response
|
||||||
} from "./http.ts";
|
} from "./mod.ts";
|
||||||
import { cwd, DenoError, ErrorKind, args, stat, readDir, open } from "deno";
|
import { cwd, DenoError, ErrorKind, args, stat, readDir, open } from "deno";
|
||||||
import { extname } from "../fs/path.ts";
|
import { extname } from "../fs/path.ts";
|
||||||
import { contentType } from "../media_types/mod.ts";
|
import { contentType } from "../media_types/mod.ts";
|
|
@ -1,8 +1,8 @@
|
||||||
import { listen, Conn, toAsyncIterator, Reader, copy } from "deno";
|
import { listen, Conn, toAsyncIterator, Reader, copy } from "deno";
|
||||||
import { BufReader, BufState, BufWriter } from "./bufio.ts";
|
import { BufReader, BufState, BufWriter } from "../io/bufio.ts";
|
||||||
import { TextProtoReader } from "./textproto.ts";
|
import { TextProtoReader } from "../textproto/mod.ts";
|
||||||
import { STATUS_TEXT } from "./http_status.ts";
|
import { STATUS_TEXT } from "./http_status.ts";
|
||||||
import { assert } from "./util.ts";
|
import { assert } from "../io/util.ts";
|
||||||
|
|
||||||
interface Deferred {
|
interface Deferred {
|
||||||
promise: Promise<{}>;
|
promise: Promise<{}>;
|
|
@ -1,5 +1,5 @@
|
||||||
import * as deno from "deno";
|
import * as deno from "deno";
|
||||||
import { serve } from "./http.ts";
|
import { serve } from "./mod.ts";
|
||||||
|
|
||||||
const addr = deno.args[1] || "127.0.0.1:4500";
|
const addr = deno.args[1] || "127.0.0.1:4500";
|
||||||
const server = serve(addr);
|
const server = serve(addr);
|
|
@ -12,8 +12,8 @@ import {
|
||||||
ServerRequest,
|
ServerRequest,
|
||||||
setContentLength,
|
setContentLength,
|
||||||
Response
|
Response
|
||||||
} from "./http.ts";
|
} from "./mod.ts";
|
||||||
import { BufWriter, BufReader } from "./bufio.ts";
|
import { BufWriter, BufReader } from "../io/bufio.ts";
|
||||||
|
|
||||||
interface ResponseTest {
|
interface ResponseTest {
|
||||||
response: Response;
|
response: Response;
|
8
http/mod.ts
Normal file
8
http/mod.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import {
|
||||||
|
serve,
|
||||||
|
listenAndServe,
|
||||||
|
Response,
|
||||||
|
setContentLength,
|
||||||
|
ServerRequest
|
||||||
|
} from "./http.ts";
|
||||||
|
export { serve, listenAndServe, Response, setContentLength, ServerRequest };
|
|
@ -1,6 +1,6 @@
|
||||||
import { remove, open, readAll } from "deno";
|
import { remove, open, readAll } from "deno";
|
||||||
import { assertEqual, test } from "../testing/mod.ts";
|
import { assertEqual, test } from "../testing/mod.ts";
|
||||||
import * as log from "index.ts";
|
import * as log from "./mod.ts";
|
||||||
import { FileHandler } from "./handlers.ts";
|
import { FileHandler } from "./handlers.ts";
|
||||||
|
|
||||||
// TODO: establish something more sophisticated
|
// TODO: establish something more sophisticated
|
15
test.ts
15
test.ts
|
@ -5,11 +5,6 @@ import "colors/test.ts";
|
||||||
import "datetime/test.ts";
|
import "datetime/test.ts";
|
||||||
import "examples/test.ts";
|
import "examples/test.ts";
|
||||||
import "flags/test.ts";
|
import "flags/test.ts";
|
||||||
import "logging/test.ts";
|
|
||||||
import "media_types/test.ts";
|
|
||||||
import "net/bufio_test.ts";
|
|
||||||
import "net/http_test.ts";
|
|
||||||
import "net/textproto_test.ts";
|
|
||||||
import "fs/mkdirp_test.ts";
|
import "fs/mkdirp_test.ts";
|
||||||
import "fs/path/basename_test.ts";
|
import "fs/path/basename_test.ts";
|
||||||
import "fs/path/dirname_test.ts";
|
import "fs/path/dirname_test.ts";
|
||||||
|
@ -20,12 +15,18 @@ import "fs/path/parse_format_test.ts";
|
||||||
import "fs/path/relative_test.ts";
|
import "fs/path/relative_test.ts";
|
||||||
import "fs/path/resolve_test.ts";
|
import "fs/path/resolve_test.ts";
|
||||||
import "fs/path/zero_length_strings_test.ts";
|
import "fs/path/zero_length_strings_test.ts";
|
||||||
|
import "io/bufio_test.ts";
|
||||||
|
import "http/http_test.ts";
|
||||||
|
import "log/test.ts";
|
||||||
|
import "media_types/test.ts";
|
||||||
import "testing/test.ts";
|
import "testing/test.ts";
|
||||||
|
import "textproto/test.ts";
|
||||||
|
import "ws/test.ts";
|
||||||
|
|
||||||
import { runTests, completePromise } from "net/file_server_test.ts";
|
import { runTests, completePromise } from "http/file_server_test.ts";
|
||||||
|
|
||||||
const fileServer = run({
|
const fileServer = run({
|
||||||
args: ["deno", "--allow-net", "net/file_server.ts", ".", "--cors"]
|
args: ["deno", "--allow-net", "http/file_server.ts", ".", "--cors"]
|
||||||
});
|
});
|
||||||
|
|
||||||
runTests(new Promise(res => setTimeout(res, 5000)));
|
runTests(new Promise(res => setTimeout(res, 5000)));
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
import { BufReader, BufState } from "./bufio.ts";
|
import { BufReader, BufState } from "../io/bufio.ts";
|
||||||
import { charCode } from "./util.ts";
|
import { charCode } from "../io/util.ts";
|
||||||
|
|
||||||
const asciiDecoder = new TextDecoder();
|
const asciiDecoder = new TextDecoder();
|
||||||
function str(buf: Uint8Array): string {
|
function str(buf: Uint8Array): string {
|
|
@ -3,9 +3,9 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
import { BufReader } from "./bufio.ts";
|
import { BufReader } from "../io/bufio.ts";
|
||||||
import { TextProtoReader, append } from "./textproto.ts";
|
import { TextProtoReader, append } from "./mod.ts";
|
||||||
import { stringsReader } from "./util.ts";
|
import { stringsReader } from "../io/util.ts";
|
||||||
import { test, assert, assertEqual } from "../testing/mod.ts";
|
import { test, assert, assertEqual } from "../testing/mod.ts";
|
||||||
|
|
||||||
function reader(s: string): TextProtoReader {
|
function reader(s: string): TextProtoReader {
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
import { Buffer, Writer, Conn } from "deno";
|
import { Buffer, Writer, Conn } from "deno";
|
||||||
import { ServerRequest } from "./http.ts";
|
import { ServerRequest } from "../http/http.ts";
|
||||||
import { BufReader, BufWriter } from "./bufio.ts";
|
import { BufReader, BufWriter } from "../io/bufio.ts";
|
||||||
import { readLong, readShort, sliceLongToBytes } from "./ioutil.ts";
|
import { readLong, readShort, sliceLongToBytes } from "../io/ioutil.ts";
|
||||||
import { Sha1 } from "./sha1.ts";
|
import { Sha1 } from "./sha1.ts";
|
||||||
|
|
||||||
export const OpCodeContinue = 0x0;
|
export const OpCodeContinue = 0x0;
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
import { Buffer } from "deno";
|
import { Buffer } from "deno";
|
||||||
import { BufReader } from "./bufio.ts";
|
import { BufReader } from "../io/bufio.ts";
|
||||||
import { test, assert, assertEqual } from "../testing/mod.ts";
|
import { test, assert, assertEqual } from "../testing/mod.ts";
|
||||||
import {
|
import {
|
||||||
createSecAccept,
|
createSecAccept,
|
||||||
|
@ -11,8 +11,8 @@ import {
|
||||||
OpCodeTextFrame,
|
OpCodeTextFrame,
|
||||||
readFrame,
|
readFrame,
|
||||||
unmask
|
unmask
|
||||||
} from "./ws.ts";
|
} from "./mod.ts";
|
||||||
import { serve } from "./http.ts";
|
import { serve } from "../http/http.ts";
|
||||||
|
|
||||||
test(async function testReadUnmaskedTextFrame() {
|
test(async function testReadUnmaskedTextFrame() {
|
||||||
// unmasked single text frame with payload "Hello"
|
// unmasked single text frame with payload "Hello"
|
Loading…
Reference in a new issue