···11-// Example: Running multiple HTTP servers on different ports
22-33-function handler8000(c) {
44- c.res.body("Server on port 8000\nURI: " + c.req.uri);
55-}
66-77-function handler8001(c) {
88- c.res.body("Server on port 8001\nURI: " + c.req.uri);
99-}
1010-1111-console.log("Starting multiple HTTP servers...");
1212-1313-// Note: Currently Ant.serve() is blocking, so you can only run one server
1414-// In the future, we could make it non-blocking to support truly concurrent servers
1515-console.log("Starting server on port 8000...");
1616-Ant.serve(8000, handler8000);
+30
tests/private_fields.js
···124124}
125125console.assert(fast.get() === 1000, "FastCounter should reach 1000");
126126127127+// Private fields may use keyword-like names
128128+class KeywordPrivate {
129129+ #var = 7;
130130+ #default = 9;
131131+132132+ sum() {
133133+ return this.#var + this.#default;
134134+ }
135135+}
136136+137137+const keywordPrivate = new KeywordPrivate();
138138+console.assert(keywordPrivate.sum() === 16, "Keyword-named private fields should parse and work");
139139+140140+// Class fields named get/set should remain fields, not accessors
141141+class FieldNamedAccessor {
142142+ #value = 0;
143143+144144+ set = (value) => {
145145+ this.#value = value;
146146+ };
147147+148148+ get = () => {
149149+ return this.#value;
150150+ };
151151+}
152152+153153+const fieldNamedAccessor = new FieldNamedAccessor();
154154+fieldNamedAccessor.set(23);
155155+console.assert(fieldNamedAccessor.get() === 23, "Field names get/set should support arrow initializers");
156156+127157console.log("All private fields tests passed!");
+6-6
tests/server.async.js
···11let count = 0;
2233-async function meow(c) {
33+async function meow() {
44 count++;
55- c.res.body(`count is ${count}`);
55+ return new Response(`count is ${count}`);
66}
7788-async function server(c) {
99- return await meow(c);
88+async function server() {
99+ return await meow();
1010}
11111212-console.log('server on http://localhost:8000');
1313-Ant.serve(8000, server);
1212+console.log('server on http://localhost:3000');
1313+export default { fetch: server };
-16
tests/server_example.cjs
···11-// Example HTTP server using Ant.serve
22-33-// Define a request handler
44-function handleRequest(c) {
55- console.log('Received request:', c.req.method, c.req.uri);
66-77- const userAgent = c.req.header('User-Agent');
88- c.res.header('X-Message', 'My custom message');
99-1010- // Return a response
1111- c.res.body('Hello from Ant HTTP Server!\nMethod: ' + c.req.method + '\nURI: ' + c.req.uri + '\nUser-Agent: ' + userAgent);
1212-}
1313-1414-// Start the server on port 8000
1515-console.log('Starting HTTP server...');
1616-Ant.serve(8000, handleRequest);
-29
tests/server_routes.cjs
···11-// Example HTTP server with basic routing
22-33-function handleRequest(c) {
44- console.log("Request:", c.req.method, c.req.uri);
55-66- // Simple routing based on URI
77- if (c.req.uri === "/") {
88- c.res.body("Welcome to Ant HTTP Server!\n\nAvailable routes:\n GET /\n GET /hello\n GET /status\n GET /echo");
99- }
1010- else if (c.req.uri === "/hello") {
1111- c.res.body("Hello, World!");
1212- }
1313- else if (c.req.uri === "/status") {
1414- c.res.header('X-Server', 'Ant');
1515- c.res.body("Server is running!");
1616- }
1717- else if (c.req.uri === "/echo") {
1818- const userAgent = c.req.header('User-Agent') || 'Unknown';
1919- c.res.body("Method: " + c.req.method + "\nURI: " + c.req.uri + "\nQuery: " + c.req.query + "\nBody: " + c.req.body + "\nUser-Agent: " + userAgent);
2020- }
2121- else {
2222- // 404 for unknown routes
2323- c.res.status(404);
2424- c.res.body("Not Found: " + c.req.uri);
2525- }
2626-}
2727-2828-console.log("Starting HTTP server on port 8000...");
2929-Ant.serve(8000, handleRequest);