-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added NetworkDeviceAttachmentWasDisconnected api #169
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8e9c1ff
added attachmentWasDisconnectedWithError delegate in internal only
Code-Hex 11f8101
use debugDescription
Code-Hex 9f38783
fix
Code-Hex f70b693
implemented Go API for attachmentWasDisconnectedWithError
Code-Hex 6f19063
supressed some warnings "note: xxx has been marked as being introduce…
Code-Hex 1eafd18
check DisconnectedError for error compatibility
Code-Hex 4be99b6
fixed FindValueByIndex logic
Code-Hex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,10 @@ | ||
package sliceutil | ||
|
||
// FindValueByIndex returns the value of the index in s, | ||
// or zero value if not present. | ||
func FindValueByIndex[S ~[]E, E any](s S, idx int) (v E) { | ||
if idx < 0 || idx >= len(s) { | ||
return v // return zero value of type E | ||
} | ||
return s[idx] | ||
} |
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,50 @@ | ||
package sliceutil_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Code-Hex/vz/v3/internal/sliceutil" | ||
) | ||
|
||
func TestFindValueByIndex(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
slice []int | ||
index int | ||
expected int | ||
}{ | ||
{ | ||
name: "Index within range", | ||
slice: []int{1, 2, 3, 4, 5}, | ||
index: 2, | ||
expected: 3, | ||
}, | ||
{ | ||
name: "Index out of range", | ||
slice: []int{1, 2, 3, 4, 5}, | ||
index: 10, | ||
expected: 0, // default value of int | ||
}, | ||
{ | ||
name: "Negative index", | ||
slice: []int{1, 2, 3, 4, 5}, | ||
index: -1, | ||
expected: 0, // default value of int | ||
}, | ||
{ | ||
name: "Empty slice", | ||
slice: []int{}, | ||
index: 0, | ||
expected: 0, // default value of int | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := sliceutil.FindValueByIndex(tt.slice, tt.index) | ||
if result != tt.expected { | ||
t.Errorf("FindValueByIndex(%v, %d) = %v; want %v", tt.slice, tt.index, result, tt.expected) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to take this concise approach because it is difficult to identify the interface NetworkDeviceAttachment class in the Objective-C world and restore it in the Go world.
This also has the advantage that it is identical to the VirtioNetworkDeviceConfiguration pointer at set time.