-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new overloading method for serve
- Loading branch information
1 parent
49b0fa1
commit c6b1efd
Showing
8 changed files
with
173 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bunny.net/edgescript-sdk": minor | ||
--- | ||
|
||
New overloading for serve to avoid putting listener |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as IP from "./ip.ts"; | ||
|
||
test('toString should convert IPv4 tuple to string', () => { | ||
const ip: IP.IPv4 = [192, 168, 1, 1]; | ||
expect(IP.toString(ip)).toBe('192.168.1.1'); | ||
}); | ||
|
||
test('tryParseFromString should parse valid IP string', () => { | ||
const ipString = '192.168.1.1'; | ||
const expected: IP.IPv4 = [192, 168, 1, 1]; | ||
expect(IP.tryParseFromString(ipString)).toEqual(expected); | ||
}); | ||
|
||
test('tryParseFromString should return SyntaxError for invalid IP string', () => { | ||
const invalidIpString = '999.999.999.999'; | ||
expect(IP.tryParseFromString(invalidIpString)).toBeInstanceOf(SyntaxError); | ||
}); | ||
|
||
test('tryParseFromString should return SyntaxError for non-numeric IP string', () => { | ||
const invalidIpString = 'abc.def.ghi.jkl'; | ||
expect(IP.tryParseFromString(invalidIpString)).toBeInstanceOf(SyntaxError); | ||
}); | ||
|
||
test('tryParseFromString should return SyntaxError for incomplete IP string', () => { | ||
const invalidIpString = '192.168.1'; | ||
expect(IP.tryParseFromString(invalidIpString)).toBeInstanceOf(SyntaxError); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { SocketAddrV4, port, tryFromString, ip } from './v4.ts'; | ||
|
||
describe('SocketAddrV4', () => { | ||
describe('port', () => { | ||
it('should return the port number', () => { | ||
const addr: SocketAddrV4 = { _tag: "SocketAddrV4", port: 8080, ip: [127, 0, 0, 1] }; | ||
expect(port(addr)).toBe(8080); | ||
}); | ||
}); | ||
|
||
describe('ip', () => { | ||
it('should return the IP address', () => { | ||
const addr: SocketAddrV4 = { _tag: "SocketAddrV4", port: 8080, ip: [127, 0, 0, 1] }; | ||
expect(ip(addr)).toStrictEqual([127, 0, 0, 1]); | ||
}); | ||
}); | ||
|
||
describe('tryFromString', () => { | ||
it('should parse a valid SocketAddrV4 string', () => { | ||
const result = tryFromString("127.0.0.1:8080"); | ||
expect(result).toEqual({ _tag: "SocketAddrV4", port: 8080, ip: [127, 0, 0, 1] }); | ||
}); | ||
|
||
it('should return a SyntaxError for an invalid IP', () => { | ||
const result = tryFromString("invalid_ip:8080"); | ||
expect(result).toBeInstanceOf(SyntaxError); | ||
expect((result as SyntaxError).message).toBe('Invalid IP address'); | ||
}); | ||
|
||
it('should return a SyntaxError for an invalid port', () => { | ||
const result = tryFromString("127.0.0.1:invalid_port"); | ||
expect(result).toBeInstanceOf(SyntaxError); | ||
expect((result as SyntaxError).message).toBe('Invalid Port'); | ||
}); | ||
|
||
it('should return a SyntaxError for a port out of range', () => { | ||
const result = tryFromString("127.0.0.1:70000"); | ||
expect(result).toBeInstanceOf(SyntaxError); | ||
expect((result as SyntaxError).message).toBe('Invalid Port'); | ||
}); | ||
|
||
it('should return a SyntaxError for an invalid format', () => { | ||
const result = tryFromString("127.0.0.1-8080"); | ||
expect(result).toBeInstanceOf(SyntaxError); | ||
expect((result as SyntaxError).message).toBe('Invalid SocketAddrV4 address'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters